fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
453 stars 75 forks source link

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

Open muqiuhan opened 11 months ago

muqiuhan commented 11 months ago

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>.$ArgumentParser.-cctor@87-1.Invoke(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

bartelink commented 9 months ago

(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])