mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Fix parse invalid property access
Fix https://github.com/dart-lang/sdk/issues/33914 and update recovery tests Change-Id: I5c0d00ffcd4d8de71b60dfc08f1109b50f3bc1e3 Reviewed-on: https://dart-review.googlesource.com/65800 Commit-Queue: Dan Rubel <danrubel@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
b4146411d0
commit
25d5d15935
|
@ -46,6 +46,7 @@ import 'package:front_end/src/fasta/messages.dart'
|
|||
messageStaticConstructor,
|
||||
messageTypedefNotFunction,
|
||||
templateDuplicateLabelInSwitchStatement,
|
||||
templateExpectedIdentifier,
|
||||
templateExpectedType;
|
||||
import 'package:front_end/src/fasta/quote.dart';
|
||||
import 'package:front_end/src/fasta/scanner/token_constants.dart';
|
||||
|
@ -491,8 +492,15 @@ class AstBuilder extends StackListener {
|
|||
..operator = dot;
|
||||
push(identifierOrInvoke);
|
||||
} else {
|
||||
unhandled("${identifierOrInvoke.runtimeType}", "property access",
|
||||
dot.charOffset, uri);
|
||||
// This same error is reported in BodyBuilder.doDotOrCascadeExpression
|
||||
Token token = identifierOrInvoke.beginToken;
|
||||
// TODO(danrubel): Consider specializing the error message based
|
||||
// upon the type of expression. e.g. "x.this" -> templateThisAsIdentifier
|
||||
handleRecoverableError(
|
||||
templateExpectedIdentifier.withArguments(token), token, token);
|
||||
SimpleIdentifier identifier =
|
||||
ast.simpleIdentifier(token, isDeclaration: false);
|
||||
push(ast.propertyAccess(receiver, dot, identifier));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4143,6 +4143,11 @@ class Wrong<T> {
|
|||
]);
|
||||
}
|
||||
|
||||
void test_invalidPropertyAccess_this() {
|
||||
parseExpression('x.this',
|
||||
errors: [expectedError(ParserErrorCode.MISSING_IDENTIFIER, 2, 4)]);
|
||||
}
|
||||
|
||||
void test_invalidStarAfterAsync() {
|
||||
createParser('foo() async* => 0;');
|
||||
CompilationUnit unit = parser.parseCompilationUnit2();
|
||||
|
|
|
@ -24,16 +24,22 @@ class IfStatementTest extends PartialCodeTest {
|
|||
new TestDescriptor(
|
||||
'leftParen',
|
||||
'if (',
|
||||
[ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN],
|
||||
[ParserErrorCode.MISSING_IDENTIFIER, ScannerErrorCode.EXPECTED_TOKEN],
|
||||
"if (_s_)",
|
||||
allFailing: true,
|
||||
failing: [
|
||||
'assert',
|
||||
'block',
|
||||
'labeled',
|
||||
'localFunctionNonVoid',
|
||||
'localFunctionVoid',
|
||||
'return'
|
||||
],
|
||||
),
|
||||
new TestDescriptor(
|
||||
'condition',
|
||||
'if (a',
|
||||
[ParserErrorCode.EXPECTED_TOKEN],
|
||||
[ScannerErrorCode.EXPECTED_TOKEN],
|
||||
"if (a)",
|
||||
allFailing: true,
|
||||
),
|
||||
],
|
||||
PartialCodeTest.statementSuffixes,
|
||||
|
|
|
@ -77,16 +77,25 @@ class WhileStatementTest extends PartialCodeTest {
|
|||
new TestDescriptor(
|
||||
'leftParen',
|
||||
'while (',
|
||||
[ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN],
|
||||
[ParserErrorCode.MISSING_IDENTIFIER, ScannerErrorCode.EXPECTED_TOKEN],
|
||||
"while (_s_)",
|
||||
allFailing: true,
|
||||
failing: [
|
||||
'assert',
|
||||
'block',
|
||||
'break',
|
||||
'continue',
|
||||
'labeled',
|
||||
'localFunctionNonVoid',
|
||||
'localFunctionVoid',
|
||||
'return'
|
||||
],
|
||||
),
|
||||
new TestDescriptor(
|
||||
'condition',
|
||||
'while (a',
|
||||
[ParserErrorCode.EXPECTED_TOKEN],
|
||||
[ScannerErrorCode.EXPECTED_TOKEN],
|
||||
"while (a)",
|
||||
allFailing: true,
|
||||
failing: ['break', 'continue'],
|
||||
),
|
||||
],
|
||||
PartialCodeTest.statementSuffixes,
|
||||
|
|
Loading…
Reference in a new issue