-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add parser test demonstrating recovery from missing type arguments in generic names. #81062
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
Changes from 4 commits
8c96da6
516c5b7
4335265
6ae8215
cea68f0
033c5d5
d4db8a1
e0dbd9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1490,5 +1490,167 @@ public void ParseGlobalAliasQualifiedNameAfterConditionalExpression() | |
| } | ||
| EOF(); | ||
| } | ||
|
|
||
| [Fact] | ||
|
||
| public void ParseGenericNameInvocationWithPartiallyOmittedTypeArguments() | ||
| { | ||
| // Tests for partially closed generic type names where the first type argument is missing | ||
| var source = """ | ||
| class C | ||
| { | ||
| void M<T1, T2>() | ||
| { | ||
| M<,int>(); // First argument omitted | ||
| M<string,>(); // Second argument omitted | ||
| M<,int,>(); // First and third arguments omitted (if we had 3 params) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot add variants with ,, as well. Also, we should validate that we get proper binding diagnostics in these cases. We don't want this to accidentally be accepted.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit cea68f0. Added |
||
| } | ||
| } | ||
| """; | ||
|
|
||
| UsingTree(source); | ||
|
|
||
| N(SyntaxKind.CompilationUnit); | ||
| { | ||
| N(SyntaxKind.ClassDeclaration); | ||
| { | ||
| N(SyntaxKind.ClassKeyword); | ||
| N(SyntaxKind.IdentifierToken, "C"); | ||
| N(SyntaxKind.OpenBraceToken); | ||
| N(SyntaxKind.MethodDeclaration); | ||
| { | ||
| N(SyntaxKind.PredefinedType); | ||
| { | ||
| N(SyntaxKind.VoidKeyword); | ||
| } | ||
| N(SyntaxKind.IdentifierToken, "M"); | ||
| N(SyntaxKind.TypeParameterList); | ||
| { | ||
| N(SyntaxKind.LessThanToken); | ||
| N(SyntaxKind.TypeParameter); | ||
| { | ||
| N(SyntaxKind.IdentifierToken, "T1"); | ||
| } | ||
| N(SyntaxKind.CommaToken); | ||
| N(SyntaxKind.TypeParameter); | ||
| { | ||
| N(SyntaxKind.IdentifierToken, "T2"); | ||
| } | ||
| N(SyntaxKind.GreaterThanToken); | ||
| } | ||
| N(SyntaxKind.ParameterList); | ||
| { | ||
| N(SyntaxKind.OpenParenToken); | ||
| N(SyntaxKind.CloseParenToken); | ||
| } | ||
| N(SyntaxKind.Block); | ||
| { | ||
| N(SyntaxKind.OpenBraceToken); | ||
| // M<,int>() | ||
| N(SyntaxKind.ExpressionStatement); | ||
| { | ||
| N(SyntaxKind.InvocationExpression); | ||
| { | ||
| N(SyntaxKind.GenericName); | ||
| { | ||
| N(SyntaxKind.IdentifierToken, "M"); | ||
| N(SyntaxKind.TypeArgumentList); | ||
| { | ||
| N(SyntaxKind.LessThanToken); | ||
| N(SyntaxKind.OmittedTypeArgument); | ||
| { | ||
| N(SyntaxKind.OmittedTypeArgumentToken); | ||
| } | ||
| N(SyntaxKind.CommaToken); | ||
| N(SyntaxKind.PredefinedType); | ||
| { | ||
| N(SyntaxKind.IntKeyword); | ||
| } | ||
| N(SyntaxKind.GreaterThanToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.ArgumentList); | ||
| { | ||
| N(SyntaxKind.OpenParenToken); | ||
| N(SyntaxKind.CloseParenToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.SemicolonToken); | ||
| } | ||
| // M<string,>() | ||
| N(SyntaxKind.ExpressionStatement); | ||
| { | ||
| N(SyntaxKind.InvocationExpression); | ||
| { | ||
| N(SyntaxKind.GenericName); | ||
| { | ||
| N(SyntaxKind.IdentifierToken, "M"); | ||
| N(SyntaxKind.TypeArgumentList); | ||
| { | ||
| N(SyntaxKind.LessThanToken); | ||
| N(SyntaxKind.PredefinedType); | ||
| { | ||
| N(SyntaxKind.StringKeyword); | ||
| } | ||
| N(SyntaxKind.CommaToken); | ||
| N(SyntaxKind.OmittedTypeArgument); | ||
| { | ||
| N(SyntaxKind.OmittedTypeArgumentToken); | ||
| } | ||
| N(SyntaxKind.GreaterThanToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.ArgumentList); | ||
| { | ||
| N(SyntaxKind.OpenParenToken); | ||
| N(SyntaxKind.CloseParenToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.SemicolonToken); | ||
| } | ||
| // M<,int,>() | ||
| N(SyntaxKind.ExpressionStatement); | ||
| { | ||
| N(SyntaxKind.InvocationExpression); | ||
| { | ||
| N(SyntaxKind.GenericName); | ||
| { | ||
| N(SyntaxKind.IdentifierToken, "M"); | ||
| N(SyntaxKind.TypeArgumentList); | ||
| { | ||
| N(SyntaxKind.LessThanToken); | ||
| N(SyntaxKind.OmittedTypeArgument); | ||
| { | ||
| N(SyntaxKind.OmittedTypeArgumentToken); | ||
| } | ||
| N(SyntaxKind.CommaToken); | ||
| N(SyntaxKind.PredefinedType); | ||
| { | ||
| N(SyntaxKind.IntKeyword); | ||
| } | ||
| N(SyntaxKind.CommaToken); | ||
| N(SyntaxKind.OmittedTypeArgument); | ||
| { | ||
| N(SyntaxKind.OmittedTypeArgumentToken); | ||
| } | ||
| N(SyntaxKind.GreaterThanToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.ArgumentList); | ||
| { | ||
| N(SyntaxKind.OpenParenToken); | ||
| N(SyntaxKind.CloseParenToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.SemicolonToken); | ||
| } | ||
| N(SyntaxKind.CloseBraceToken); | ||
| } | ||
| } | ||
| N(SyntaxKind.CloseBraceToken); | ||
| } | ||
| N(SyntaxKind.EndOfFileToken); | ||
| } | ||
| EOF(); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot switch this to a conditinoal expression like so:
Do the same in the other code change you had below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit cea68f0. Refactored both locations to use conditional expressions.