提交 4c00cec0 编写于 作者: N Neal Gafter 提交者: GitHub

Fix a crash in the parser due to ParseStatementCore returning null (#19281)

Other call sites appear to have been adapted already.
Fixes https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=266237
上级 86e3f08b
......@@ -8222,7 +8222,7 @@ private LabeledStatementSyntax ParseLabeledStatement()
var label = this.ParseIdentifierToken();
var colon = this.EatToken(SyntaxKind.ColonToken);
Debug.Assert(!colon.IsMissing);
var statement = this.ParseStatementCore();
var statement = this.ParseStatementCore() ?? SyntaxFactory.EmptyStatement(EatToken(SyntaxKind.SemicolonToken));
return _syntaxFactory.LabeledStatement(label, colon, statement);
}
......
......@@ -2705,6 +2705,23 @@ public void TestRunEmbeddedStatementNotFollowedBySemicolon()
Assert.Equal((int)ErrorCode.ERR_SemicolonExpected, statement.Errors()[0].Code);
}
[WorkItem(266237, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=266237")]
[Fact]
public void NullExceptionInLabeledStatement()
{
UsingStatement(@"{ label: public",
// (1,1): error CS1073: Unexpected token 'public'
// { label: public
Diagnostic(ErrorCode.ERR_UnexpectedToken, "{ label: ").WithArguments("public").WithLocation(1, 1),
// (1,10): error CS1002: ; expected
// { label: public
Diagnostic(ErrorCode.ERR_SemicolonExpected, "public").WithLocation(1, 10),
// (1,10): error CS1513: } expected
// { label: public
Diagnostic(ErrorCode.ERR_RbraceExpected, "public").WithLocation(1, 10)
);
}
private sealed class TokenAndTriviaWalker : CSharpSyntaxWalker
{
public int Tokens;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册