提交 a4191efd 编写于 作者: A AlekseyTs 提交者: GitHub

Merge pull request #17827 from AlekseyTs/Issue17458_2

Ensure LanguageParser.ParseStatement doesn’t return null.
......@@ -6488,7 +6488,7 @@ private TypeSyntax ParsePointerTypeMods(TypeSyntax type)
public StatementSyntax ParseStatement()
{
return ParseWithStackGuard(
ParseStatementCore,
() => ParseStatementCore() ?? ParseExpressionStatement(),
() => SyntaxFactory.EmptyStatement(SyntaxFactory.MissingToken(SyntaxKind.SemicolonToken)));
}
......
......@@ -6,16 +6,45 @@
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class StatementParsingTests
public class StatementParsingTests : ParsingTests
{
public StatementParsingTests(ITestOutputHelper output) : base(output) { }
private StatementSyntax ParseStatement(string text, int offset = 0, ParseOptions options = null)
{
return SyntaxFactory.ParseStatement(text, offset, options);
}
[Fact]
[WorkItem(17458, "https://github.com/dotnet/roslyn/issues/17458")]
public void ParsePrivate()
{
UsingStatement("private",
// (1,1): error CS1073: Unexpected token 'private'
// private
Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("private").WithLocation(1, 1),
// (1,1): error CS1525: Invalid expression term 'private'
// private
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "private").WithArguments("private").WithLocation(1, 1),
// (1,1): error CS1002: ; expected
// private
Diagnostic(ErrorCode.ERR_SemicolonExpected, "private").WithLocation(1, 1)
);
M(SyntaxKind.ExpressionStatement);
{
M(SyntaxKind.IdentifierName);
{
M(SyntaxKind.IdentifierToken);
}
M(SyntaxKind.SemicolonToken);
}
EOF();
}
[Fact]
public void TestName()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册