fix(generator): treat [ArgumentParser] on collection property as whole-collection parser#52
Merged
Conversation
…e-collection parser When [ArgumentParser(typeof(P))] is placed on an IReadOnlySet<T> (or any collection-typed) property/parameter, the generator was routing it through BuildCollectionParameterModel and calling P.TryParse per element, then trying to Add the IReadOnlySet<T> result into a HashSet<T> — a type mismatch when P implements IArgumentParser<IReadOnlySet<T>>. The fix: guard all five TryUnwrapCollectionType call sites with TryParserTypeFqFromSymbol(symbol) is null. When [ArgumentParser] is present, the property falls through to the scalar ClassifyScalarUnified path, which classifies it as CliScalarKind.CustomParser with CustomValueTypeFq equal to the full collection type. The emitter then generates a single flags.TryGetValue lookup and a direct parser.TryParse assignment — exactly the desired behavior. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[ArgumentParser(typeof(P))]is placed on anIReadOnlySet<T>(or any collection-typed) property/parameter, the generator was routing it throughBuildCollectionParameterModeland callingP.TryParseper element, then trying toAddtheIReadOnlySet<T>result into aHashSet<T>— a type mismatch whenPimplementsIArgumentParser<IReadOnlySet<T>>.TryUnwrapCollectionTypecall sites withTryParserTypeFqFromSymbol(symbol) is null. When[ArgumentParser]is present, the property falls through to the scalarClassifyScalarUnifiedpath, which classifies it asCliScalarKind.CustomParserwithCustomValueTypeFqequal to the full collection type.flags.TryGetValuelookup and a directparser.TryParseassignment — the correct behavior for a whole-collection parser.Generated code before (broken)
Generated code after (correct)
Test plan
WholeCollection_ArgumentParser_on_IReadOnlySet_parameter— required flag, comma-separated value parsed byStringSetParser : IArgumentParser<IReadOnlySet<string>>WholeCollection_ArgumentParser_on_nullable_IReadOnlySet_parameter_when_provided— optional, value presentWholeCollection_ArgumentParser_on_nullable_IReadOnlySet_parameter_when_absent— optional, flag omitted → null🤖 Generated with Claude Code