From 0851ac876cc168cc09576905e5fb6a2cb72edf34 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Tue, 13 Dec 2016 17:15:46 -0800 Subject: [PATCH] UPdate how we parse MemberAccess expressions as well. --- .../CSharp/Portable/Parser/LanguageParser.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 629291df59887..cb325316d24c1 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -9678,6 +9678,26 @@ private ExpressionSyntax ParsePostFixExpression(ExpressionSyntax expr) expr = _syntaxFactory.MemberAccessExpression(SyntaxKind.PointerMemberAccessExpression, expr, this.EatToken(), this.ParseSimpleName(NameOptions.InExpression)); break; case SyntaxKind.DotToken: + // if we have the error situation: + // + // expr. + // X Y + // + // Then we don't want to parse this out as "Expr.X" + // + // It's far more likely the member access expression is simply incomplete and + // 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) + { + expr = _syntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, expr, this.EatToken(), + this.AddError(this.CreateMissingIdentifierName(), ErrorCode.ERR_IdentifierExpected)); + + return expr; + } + expr = _syntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, expr, this.EatToken(), this.ParseSimpleName(NameOptions.InExpression)); break;