Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Reflection.AmbiguousMatchException occurs when CLIArguments contains Tag #185

Open
muqiuhan opened this issue Oct 16, 2023 · 1 comment

Comments

@muqiuhan
Copy link

Description

When CLIArguments contains Tag, such as:

...
[<RequireQualifiedAccess>]
type CLIArguments =
    | Version
    | [<CliPrefix(CliPrefix.None)>] Add
    | [<CliPrefix(CliPrefix.None)>] Init
    | [<CliPrefix(CliPrefix.None)>] Log
    | [<CliPrefix(CliPrefix.None)>] Rm
    | [<CliPrefix(CliPrefix.None)>] Tag // Here
    | [<CliPrefix(CliPrefix.None)>] Status
    | [<CliPrefix(CliPrefix.None)>] Cat_File
    | [<CliPrefix(CliPrefix.None)>] Check_Ignore
    | [<CliPrefix(CliPrefix.None)>] Checkout
    | [<CliPrefix(CliPrefix.None)>] Commit
    | [<CliPrefix(CliPrefix.None)>] Hash_Object
    | [<CliPrefix(CliPrefix.None)>] Ls_Files
    | [<CliPrefix(CliPrefix.None)>] Ls_Tree
    | [<CliPrefix(CliPrefix.None)>] Rev_Parse
    | [<CliPrefix(CliPrefix.None)>] Show_Ref
...

System.Reflection.AmbiguousMatchException will be thrown at runtime:
image

And if I rename the Tag to another name, it will work.

text:

Unhandled exception. System.Reflection.AmbiguousMatchException: Ambiguous match found for 'vercos.Argu+CLIArguments CLIArguments get_Tag()'.
   at System.DefaultBinder.FindMostDerivedNewSlotMeth(MethodBase[] match, Int32 cMatches)
   at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetMethod(String name, BindingFlags bindingAttr)
   at Microsoft.FSharp.Reflection.Impl.getUnionCaseConstructorMethod(Type typ, Int32 tag, BindingFlags bindingFlags) in D:\a\_work\1\s\src\FSharp.Core\reflect.fs:line 602
   at Microsoft.FSharp.Reflection.Impl.getUnionCaseConstructorCompiled(Type typ, Int32 tag, BindingFlags bindingFlags) in D:\a\_work\1\s\src\FSharp.Core\reflect.fs:line 615
   at Microsoft.FSharp.Reflection.FSharpValue.PreComputeUnionConstructor(UnionCaseInfo unionCase, FSharpOption`1 bindingFlags) in D:\a\_work\1\s\src\FSharp.Core\reflect.fs:line 1370
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Argu.PreCompute.postProcess@648(UnionArgInfo argInfo)
   at Argu.PreCompute.checkUnionArgInfo(UnionArgInfo result)
   at <StartupCode$Argu>[email protected](Unit unitVar)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Argu.ArgumentParser`1..ctor(FSharpOption`1 programName, FSharpOption`1 helpTextMessage, FSharpOption`1 usageStringCharacterWidth, FSharpOption`1 errorHandler, FSharpOption`1 checkStructure)
   at Argu.ArgumentParser.Create[Template](FSharpOption`1 programName, FSharpOption`1 helpTextMessage, FSharpOption`1 usageStringCharacterWidth, FSharpOption`1 errorHandler, FSharpOption`1 checkStructure)
   at vercos.Argu.Parser.get_parser() in /home/muqiu-han/Workspace/vercos/vercos/Argu.fs:line 62
   at vercos.Argu.Parser.Parse(String[] argv) in /home/muqiu-han/Workspace/vercos/vercos/Argu.fs:line 64
   at vercos.Main.main(String[] argv) in /home/muqiu-han/Workspace/vercos/vercos/Program.fs:line 

Related information

  • Operating system: Linux
  • Argu Version: 6.1.1
  • .NET Core Version: 8.0.100-rc.2.23502.2
@bartelink
Copy link
Member

(This is likely due to Tag being a compiler generated property that DU instances bear. Such artifacts are likely to be decorated with CompilerGeneratedAttribute [which might be part of the resolution of this issue])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants