提交 0bb78946 编写于 作者: N Neal Gafter 提交者: GitHub

Refine syntax error recovery for partial code to not interfere with non-error code. (#17692)

Related to #15885
Fixes #17683
上级 a4191efd
......@@ -9413,7 +9413,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(),
......
......@@ -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();
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册