Skip to content

Handle unexpected keyword rather than identifier for lambda parameter name#60825

Merged
cston merged 7 commits intodotnet:mainfrom
cston:60661
Apr 25, 2022
Merged

Handle unexpected keyword rather than identifier for lambda parameter name#60825
cston merged 7 commits intodotnet:mainfrom
cston:60661

Conversation

@cston
Copy link
Copy Markdown
Contributor

@cston cston commented Apr 18, 2022

Fixes #60661

@ghost ghost added the Area-Compilers label Apr 18, 2022
{
static void Main()
{
Action<int> a = int => { };
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 Apr 19, 2022

Choose a reason for hiding this comment

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

Consider adding another test for public. Currently the behavior for int (stack exhausting) is different than public (too many syntax errors).

Also consider testing with @int (not too important) #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a parsing test for a full syntax tree with public.

@cston cston marked this pull request as ready for review April 19, 2022 19:00
@cston cston requested a review from a team as a code owner April 19, 2022 19:00
@cston
Copy link
Copy Markdown
Contributor Author

cston commented Apr 21, 2022

@dotnet/roslyn-compiler, please review, thanks.

@RikkiGibson RikkiGibson self-assigned this Apr 21, 2022
// x => ...
// x!! => ...
var identifier = this.ParseIdentifierToken();
var identifier = (this.CurrentToken.Kind != SyntaxKind.IdentifierToken && this.PeekToken(1).Kind == SyntaxKind.EqualsGreaterThanToken) ?
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Apr 22, 2022

Choose a reason for hiding this comment

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

Could you clarify why we need to peek for an => here? It seems like we already scanned and determined that this is a lambda? #Resolved

Copy link
Copy Markdown
Contributor Author

@cston cston Apr 22, 2022

Choose a reason for hiding this comment

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

The lambda expression may be x => ... or just => ... (missing parameter name).

@cston
Copy link
Copy Markdown
Contributor Author

cston commented Apr 25, 2022

@dotnet/roslyn-compiler, please review, thanks.

// x => ...
// x!! => ...
var identifier = this.ParseIdentifierToken();
var identifier = (this.CurrentToken.Kind != SyntaxKind.IdentifierToken && this.PeekToken(1).Kind == SyntaxKind.EqualsGreaterThanToken) ?
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 25, 2022

Choose a reason for hiding this comment

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

Should we also condition on whether there's a !! token?
Never mind, we're removing that feature. #Closed

Copy link
Copy Markdown
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 4)

@jcouv jcouv self-assigned this Apr 25, 2022
Copy link
Copy Markdown
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.

LGTM (commit 6)

[Theory]
public void KeywordParameterName_01(LanguageVersion languageVersion)
{
string source = "int =>";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this only an issue for non-parenthesized lambdas? What if we had (int, int) =>?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might also be good to just test (int) => as well.

@cston cston merged commit cc00ddf into dotnet:main Apr 25, 2022
@cston cston deleted the 60661 branch April 25, 2022 20:56
@ghost ghost added this to the Next milestone Apr 25, 2022
@cston cston modified the milestones: Next, 17.3 Apr 25, 2022
333fred added a commit that referenced this pull request Apr 26, 2022
…ures/semi-auto-props

* upstream/main: (266 commits)
  Pass fallback options (#60803)
  Rename `CodeStyleHostLanguageServices.cs.cs` to `CodeStyleHostLanguageServices.cs` (#60955)
  Allow VSMac to access LSP options (#60943)
  Add configs for 17.3 branch and update main version (#60942)
  Restore nugetKind config to publish data
  Remove unnecessary publish data config
  Remove non-servicing 15.x publish config
  Let 'arcade' packageFeeds imply all feeds are 'arcade'
  Remove non-servicing branches from our PublishData
  Handle unexpected keyword rather than identifier for lambda parameter name (#60825)
  Correctly return E_NOTIMPL when asked for file code models for non-source
  Move the resources to top (#60899)
  Add back deprecated packages to arcade publishing config.
  Simplify
  Rename parameter
  Simplify visibility logic in tagger
  Simplify visibility logic in tagger
  Try out some fixes
  Update StructConstructorTests.cs
  Use more descriptive variable name
  ...
333fred added a commit that referenced this pull request Apr 26, 2022
…ures/required-members

* upstream/main: (156 commits)
  Pass fallback options (#60803)
  Rename `CodeStyleHostLanguageServices.cs.cs` to `CodeStyleHostLanguageServices.cs` (#60955)
  Allow VSMac to access LSP options (#60943)
  Add configs for 17.3 branch and update main version (#60942)
  Restore nugetKind config to publish data
  Remove unnecessary publish data config
  Remove non-servicing 15.x publish config
  Let 'arcade' packageFeeds imply all feeds are 'arcade'
  Remove non-servicing branches from our PublishData
  Handle unexpected keyword rather than identifier for lambda parameter name (#60825)
  Correctly return E_NOTIMPL when asked for file code models for non-source
  Move the resources to top (#60899)
  Add back deprecated packages to arcade publishing config.
  Simplify
  Rename parameter
  Simplify visibility logic in tagger
  Simplify visibility logic in tagger
  Try out some fixes
  Update StructConstructorTests.cs
  Use more descriptive variable name
  ...
333fred added a commit to 333fred/roslyn that referenced this pull request Apr 27, 2022
…o forbid-new

* upstream/features/required-members: (156 commits)
  Pass fallback options (dotnet#60803)
  Rename `CodeStyleHostLanguageServices.cs.cs` to `CodeStyleHostLanguageServices.cs` (dotnet#60955)
  Allow VSMac to access LSP options (dotnet#60943)
  Add configs for 17.3 branch and update main version (dotnet#60942)
  Restore nugetKind config to publish data
  Remove unnecessary publish data config
  Remove non-servicing 15.x publish config
  Let 'arcade' packageFeeds imply all feeds are 'arcade'
  Remove non-servicing branches from our PublishData
  Handle unexpected keyword rather than identifier for lambda parameter name (dotnet#60825)
  Correctly return E_NOTIMPL when asked for file code models for non-source
  Move the resources to top (dotnet#60899)
  Add back deprecated packages to arcade publishing config.
  Simplify
  Rename parameter
  Simplify visibility logic in tagger
  Simplify visibility logic in tagger
  Try out some fixes
  Update StructConstructorTests.cs
  Use more descriptive variable name
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda using 'sbyte' as parameter name overflows the parsing stack

5 participants