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

Improve generic type argument list error recovery #69734

Merged
merged 29 commits into from
Apr 2, 2024

Conversation

Rekkonnect
Copy link
Contributor

@Rekkonnect Rekkonnect commented Aug 27, 2023

Fixes #24642
Fixes #48566

Also improves error recovery in bad tuple type arguments of the form (a x, b y) c.

Some erroneous code cases were also adjusted; the parser now leans more towards parsing generics than comparison expressions, only to improve error recovery.

The parser's logic now is:

After a successfully parsed type argument, if we fail to find a comma separator, we look forward. If the next token is an identifier token, followed by either of the following: ( ) { } ; = => < this operator or and not, we then consider the type argument list as complete, with a missing > token closing it.
Otherwise, if the next token is an identifier token, followed by a ] token and any of the above tokens, we consider the type argument list as complete. This was specifically added to handle the parameter list in a this accessor.

@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Aug 27, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 27, 2023
@Rekkonnect Rekkonnect marked this pull request as ready for review August 27, 2023 09:42
@Rekkonnect Rekkonnect requested a review from a team as a code owner August 27, 2023 09:42
@Rekkonnect Rekkonnect changed the title Generic method error recovery Improve generic type argument list error recovery Aug 27, 2023
@Rekkonnect Rekkonnect requested a review from a team as a code owner August 28, 2023 08:52
@jcouv jcouv self-assigned this Aug 28, 2023
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 9)

@jcouv
Copy link
Member

jcouv commented Aug 28, 2023

@dotnet/roslyn-compiler for second review. Thanks

or SyntaxKind.OpenBraceToken
or SyntaxKind.CloseBraceToken
or SyntaxKind.EqualsToken
or SyntaxKind.EqualsGreaterThanToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to see examples of all of the above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests for each of these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of those might be missing some tests, will make another pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment still applies. i want to know why each of those cases are something that would break the argument list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment still applies. :)

case SyntaxKind.OrKeyword:
case SyntaxKind.AndKeyword:
case SyntaxKind.NotKeyword:
return true;
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give an example of where this arises (in a code comment). #Closed

// Example: IEnumerable<string Method<T>()
is SyntaxKind.LessThanToken
// Example: Method<string(argument)
or SyntaxKind.OpenParenToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would break these into separate 'if' checks. Different ones warrant different comments. For example, for this, i would mention, this means we'll do a bad job with Method<string (int a, ... where the ( starts a tuple type argument. But that we're ok with taht as we don't want to look that far ahead, and we feel like it's more likely that it's a parameter list.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing off, with small nit requests.

@CyrusNajmabadi
Copy link
Member

@dotnet/roslyn-compiler for another set of eyes. thanks!

@jaredpar jaredpar added this to the 17.9 milestone Oct 2, 2023
@jcouv jcouv dismissed stale reviews from 333fred and themself January 30, 2024 18:35

Code changed

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 27)

@jcouv jcouv requested a review from 333fred January 30, 2024 18:36
@jaredpar
Copy link
Member

jaredpar commented Apr 1, 2024

@333fred for the second review here.

@jaredpar jaredpar modified the milestones: 17.9, 17.11 Apr 1, 2024
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly this looks good to me. Just a few comments.

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs Outdated Show resolved Hide resolved
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs Outdated Show resolved Hide resolved
// Example: x is IEnumerable<string or IList<int>
case SyntaxKind.OrKeyword:
// Example: x is IEnumerable<string and IDisposable
case SyntaxKind.AndKeyword:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests for tuple types where the tuple type name is and or or and the tuple is unterminated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to see a few tests with missing tuple end ). For example: IEnumerable<(string Value, string Description Values { get; }

@Rekkonnect Rekkonnect requested a review from 333fred April 2, 2024 15:42
@333fred 333fred merged commit 399051e into dotnet:main Apr 2, 2024
30 checks passed
@Rekkonnect Rekkonnect deleted the generic-method-error-recovery branch April 2, 2024 16:32
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 17.11, Next Apr 2, 2024
@333fred
Copy link
Member

333fred commented Apr 2, 2024

Thanks @Rekkonnect!

333fred added a commit to 333fred/roslyn that referenced this pull request Apr 3, 2024
* upstream/main: (416 commits)
  Semantic search (dotnet#71268)
  Make more static
  Fix MEF import of IExternalCSharpCopilotCodeAnalysisService to allow null
  Make static
  Make private
  Add comments
  Add method name to TimeInQueue telemetry (dotnet#72841)
  switch to frozen
  Simplify
  Add test
  Downstream
  Use singular helper when creating checksumsw
  Use singular helper when creating checksumsw
  Remove ability for a project to change its language
  Revert "Avoid creating result temp for is-expressions (dotnet#72273)" (dotnet#72827)
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2420199
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2420199
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2420199
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2420199
  Improve generic type argument list error recovery (dotnet#69734)
  ...
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unintuitive diagnostic when missing > in type argument list Poor error recovery after missing >
6 participants