Fix keyword infinite loop
Change-Id: I92bee9991400c229bbf665414a096efae72c14c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113126
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
Auto-Submit: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
diff --git a/pkg/analyzer/test/generated/invalid_code_test.dart b/pkg/analyzer/test/generated/invalid_code_test.dart
index 778ecc8..ab6e289 100644
--- a/pkg/analyzer/test/generated/invalid_code_test.dart
+++ b/pkg/analyzer/test/generated/invalid_code_test.dart
@@ -89,6 +89,38 @@
''');
}
+ test_keywordInConstructorInitializer_assert() async {
+ await _assertCanBeAnalyzed('''
+class C {
+ C() : assert = 0;
+}
+''');
+ }
+
+ test_keywordInConstructorInitializer_null() async {
+ await _assertCanBeAnalyzed('''
+class C {
+ C() : null = 0;
+}
+''');
+ }
+
+ test_keywordInConstructorInitializer_super() async {
+ await _assertCanBeAnalyzed('''
+class C {
+ C() : super = 0;
+}
+''');
+ }
+
+ test_keywordInConstructorInitializer_this() async {
+ await _assertCanBeAnalyzed('''
+class C {
+ C() : this = 0;
+}
+''');
+ }
+
Future<void> _assertCanBeAnalyzed(String text) async {
addTestFile(text);
await resolveTestFile();
diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart
index ec05f20..a50ba2f 100644
--- a/pkg/front_end/lib/src/fasta/parser/parser.dart
+++ b/pkg/front_end/lib/src/fasta/parser/parser.dart
@@ -2545,9 +2545,6 @@
++count;
next = token.next;
if (!optional(',', next)) {
- if (!next.isKeywordOrIdentifier) {
- break;
- }
// Recovery: Found an identifier which could be
// 1) missing preceding `,` thus it's another initializer, or
// 2) missing preceding `;` thus it's a class member, or
@@ -2558,6 +2555,9 @@
break;
}
// Looks like assert expression ... fall through to insert comma
+ } else if (!next.isIdentifier && !optional('this', next)) {
+ // An identifier that wasn't an initializer. Break.
+ break;
} else {
if (optional('this', next)) {
next = next.next;
@@ -2565,7 +2565,7 @@
break;
}
next = next.next;
- if (!next.isKeywordOrIdentifier) {
+ if (!next.isIdentifier && !optional('assert', next)) {
break;
}
}