Skip to content

Commit ddde982

Browse files
danrubelcommit-bot@chromium.org
authored andcommitted
Improve fasta parser parameter list recovery
... and update more Analyzer fasta tests. Change-Id: Ia6e9e08cca1a1c81528767e5c0b2f18435cd8ea9 Reviewed-on: https://dart-review.googlesource.com/61000 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Dan Rubel <danrubel@google.com>
1 parent f5a0e3e commit ddde982

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
2525
import 'test_support.dart';
2626

2727
main() {
28+
// The fasta parser has a parallel set of tests in parser_fasta_test.dart
29+
if (Parser.useFasta) return;
30+
2831
defineReflectiveSuite(() {
2932
defineReflectiveTests(ClassMemberParserTest);
3033
defineReflectiveTests(ComplexParserTest);

pkg/analyzer/test/src/summary/summary_common.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8760,10 +8760,15 @@ D d;''');
87608760
serializeLibraryText('@a(-b=""c');
87618761
expect(unlinkedUnits, hasLength(1));
87628762
List<UnlinkedVariable> variables = unlinkedUnits[0].variables;
8763-
expect(variables, hasLength(1));
8764-
List<UnlinkedExpr> annotations = variables[0].annotations;
8765-
expect(annotations, hasLength(1));
8766-
expect(annotations[0].isValidConst, isFalse);
8763+
if (Parser.useFasta) {
8764+
// Fasta recovers by appending `)` after `c`
8765+
expect(variables, isEmpty);
8766+
} else {
8767+
expect(variables, hasLength(1));
8768+
List<UnlinkedExpr> annotations = variables[0].annotations;
8769+
expect(annotations, hasLength(1));
8770+
expect(annotations[0].isValidConst, isFalse);
8771+
}
87678772
}
87688773

87698774
test_metadata_invalid_instanceCreation_argument_super() {

pkg/front_end/lib/src/fasta/parser/parser.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,12 @@ class Parser {
11891189
// Scanner has already reported a missing `)` error,
11901190
// but placed the `)` in the wrong location, so move it.
11911191
token = rewriter.moveSynthetic(token, begin.endGroup);
1192+
} else if (next.kind == IDENTIFIER_TOKEN &&
1193+
next.next.kind == IDENTIFIER_TOKEN) {
1194+
// Looks like a missing comma
1195+
Token comma = new SyntheticToken(TokenType.COMMA, next.charOffset);
1196+
token = rewriter.insertTokenAfter(token, comma).next;
1197+
continue;
11921198
} else {
11931199
reportRecoverableError(
11941200
next, fasta.templateExpectedButGot.withArguments(')'));

0 commit comments

Comments
 (0)