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

NullReferenceException in SyntaxFactory.ParseStatement() #17458

Closed
KirillOsenkov opened this issue Feb 28, 2017 · 0 comments
Closed

NullReferenceException in SyntaxFactory.ParseStatement() #17458

KirillOsenkov opened this issue Feb 28, 2017 · 0 comments
Assignees
Labels
Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@KirillOsenkov
Copy link
Member

Version Used:
NuGet Microsoft.CodeAnalysis 2.0.0-rc4

Steps to Reproduce:

  1. New C# console app, install Microsoft.CodeAnalysis package version 2.0.0-rc4
  2. Program.cs method body: SyntaxFactory.ParseStatement("private");

Expected Behavior:
Does not crash

Actual Behavior:
NullReferenceException:

Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxParser.AddError<Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.StatementSyntax> Line 702	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.LanguageParser.ConsumeUnexpectedTokens<Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.StatementSyntax> Line 11847	C#
>	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ParseStatement Line 1780	C#
 	RoslynApp1.exe!RoslynApp1.Program.Main Line 14	C#

This is because here we don't check the node for null:
http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Syntax/SyntaxFactory.cs,1780

@gafter gafter added Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. labels Feb 28, 2017
@gafter gafter added this to the 2.1 milestone Feb 28, 2017
@AlekseyTs AlekseyTs self-assigned this Mar 8, 2017
@jaredpar jaredpar modified the milestones: 15.3, 15.1 Mar 9, 2017
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Mar 13, 2017
Fixes dotnet#17458.
Heuristics around local functions can cause both ParseStatementNoDeclaration and ParsePossibleDeclarationOrBadAwaitStatement to return null in case of an error. LanguageParser.ParseStatementCore is modified to recover from this situation by parsing an expression statement.
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Mar 14, 2017
Fixes dotnet#17458.
LanguageParser.ParseStatement can return null in case of an error. LanguageParser.ParseStatement is modified to recover from this situation by parsing an expression statement.
@AlekseyTs AlekseyTs added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 3 - Working labels Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

4 participants