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

Ensure LanguageParser.ParseStatement doesn’t return null. #17827

Merged
merged 1 commit into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6488,7 +6488,7 @@ private TypeSyntax ParsePointerTypeMods(TypeSyntax type)
public StatementSyntax ParseStatement()
{
return ParseWithStackGuard(
ParseStatementCore,
() => ParseStatementCore() ?? ParseExpressionStatement(),
() => SyntaxFactory.EmptyStatement(SyntaxFactory.MissingToken(SyntaxKind.SemicolonToken)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down