Skip to content

Commit

Permalink
Refine syntax error recovery for partial code to not interfere with n…
Browse files Browse the repository at this point in the history
…on-error code.

Related to dotnet#15885
Fixes dotnet#17683
  • Loading branch information
gafter committed Mar 10, 2017
1 parent 0d9d661 commit d78fda7
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
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 @@ -9386,7 +9386,7 @@ private ExpressionSyntax ParsePostFixExpression(ExpressionSyntax expr)
// there is a new declaration on the next line.
if (this.CurrentToken.TrailingTrivia.Any((int)SyntaxKind.EndOfLineTrivia) &&
this.PeekToken(1).Kind == SyntaxKind.IdentifierToken &&
this.PeekToken(2).Kind == SyntaxKind.IdentifierToken)
this.PeekToken(2).ContextualKind == SyntaxKind.IdentifierToken)
{
expr = _syntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression, expr, this.EatToken(),
Expand Down
122 changes: 122 additions & 0 deletions src/Compilers/CSharp/Test/Syntax/Parsing/ExpressionParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3533,5 +3533,127 @@ void M()
EOF();
}

[Fact, WorkItem(17683, "https://github.com/dotnet/roslyn/issues/17683")]
public void Bug17683a()
{
var source =
@"from t in e
where
t == Int32.
MinValue
select t";
UsingExpression(source);
N(SyntaxKind.QueryExpression);
{
N(SyntaxKind.FromClause);
{
N(SyntaxKind.FromKeyword);
N(SyntaxKind.IdentifierToken, "t");
N(SyntaxKind.InKeyword);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "e");
}
}
N(SyntaxKind.QueryBody);
{
N(SyntaxKind.WhereClause);
{
N(SyntaxKind.WhereKeyword);
N(SyntaxKind.EqualsExpression);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "t");
}
N(SyntaxKind.EqualsEqualsToken);
N(SyntaxKind.SimpleMemberAccessExpression);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "Int32");
}
N(SyntaxKind.DotToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "MinValue");
}
}
}
}
N(SyntaxKind.SelectClause);
{
N(SyntaxKind.SelectKeyword);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "t");
}
}
}
}
EOF();
}

[Fact]
public void Bug17683b()
{
var source =
@"switch (e)
{
case Int32.
MaxValue when true:
break;
}";
UsingStatement(source);
N(SyntaxKind.SwitchStatement);
{
N(SyntaxKind.SwitchKeyword);
N(SyntaxKind.OpenParenToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "e");
}
N(SyntaxKind.CloseParenToken);
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.SwitchSection);
{
N(SyntaxKind.CasePatternSwitchLabel);
{
N(SyntaxKind.CaseKeyword);
N(SyntaxKind.ConstantPattern);
{
N(SyntaxKind.SimpleMemberAccessExpression);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "Int32");
}
N(SyntaxKind.DotToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "MaxValue");
}
}
}
N(SyntaxKind.WhenClause);
{
N(SyntaxKind.WhenKeyword);
N(SyntaxKind.TrueLiteralExpression);
{
N(SyntaxKind.TrueKeyword);
}
}
N(SyntaxKind.ColonToken);
}
N(SyntaxKind.BreakStatement);
{
N(SyntaxKind.BreakKeyword);
N(SyntaxKind.SemicolonToken);
}
}
N(SyntaxKind.CloseBraceToken);
}
EOF();
}
}
}

0 comments on commit d78fda7

Please sign in to comment.