Skip to content

Commit 5c508ff

Browse files
danrubelcommit-bot@chromium.org
danrubel
authored andcommitted
Update more IdentifierContext type reference recovery
Change-Id: I7268bce4379ac4613ecd182c9d41022f2a08e7c4 Reviewed-on: https://dart-review.googlesource.com/50521 Commit-Queue: Dan Rubel <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 8054721 commit 5c508ff

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9147,7 +9147,12 @@ abstract class FormalParameterParserTestMixin
91479147

91489148
void test_parseFormalParameterList_prefixedType_partial() {
91499149
FormalParameterList list = parseFormalParameterList('(io.)', errors: [
9150-
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 4, 1),
9150+
expectedError(
9151+
usingFastaParser
9152+
? ParserErrorCode.EXPECTED_TYPE_NAME
9153+
: ParserErrorCode.MISSING_IDENTIFIER,
9154+
4,
9155+
1),
91519156
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 4, 1)
91529157
]);
91539158
expect(list, isNotNull);
@@ -9169,7 +9174,12 @@ abstract class FormalParameterParserTestMixin
91699174
void test_parseFormalParameterList_prefixedType_partial2() {
91709175
int errorOffset = usingFastaParser ? 4 : 3;
91719176
FormalParameterList list = parseFormalParameterList('(io.,a)', errors: [
9172-
expectedError(ParserErrorCode.MISSING_IDENTIFIER, errorOffset, 1),
9177+
expectedError(
9178+
usingFastaParser
9179+
? ParserErrorCode.EXPECTED_TYPE_NAME
9180+
: ParserErrorCode.MISSING_IDENTIFIER,
9181+
errorOffset,
9182+
1),
91739183
expectedError(ParserErrorCode.MISSING_IDENTIFIER, errorOffset, 1)
91749184
]);
91759185
expect(list, isNotNull);

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import '../../scanner/token.dart' show Token;
66

7-
import '../fasta_codes.dart'
8-
show Message, Template, templateExpectedIdentifier, templateExpectedType;
7+
import '../fasta_codes.dart' show Message, Template, templateExpectedIdentifier;
98

109
import '../scanner/token_constants.dart' show IDENTIFIER_TOKEN;
1110

@@ -119,21 +118,16 @@ class IdentifierContext {
119118
isBuiltInIdentifierAllowed: false);
120119

121120
/// Identifier is the start of a reference to a type that starts with prefix.
122-
static const prefixedTypeReference = const IdentifierContext(
123-
'prefixedTypeReference',
124-
isScopeReference: true,
125-
isBuiltInIdentifierAllowed: true,
126-
recoveryTemplate: templateExpectedType);
121+
static const prefixedTypeReference =
122+
const TypeReferenceIdentifierContext.prefixed();
127123

128124
/// Identifier is the start of a reference to a type declared elsewhere.
129125
static const typeReference = const TypeReferenceIdentifierContext();
130126

131127
/// Identifier is part of a reference to a type declared elsewhere, but it's
132128
/// not the first identifier of the reference.
133-
static const typeReferenceContinuation = const IdentifierContext(
134-
'typeReferenceContinuation',
135-
isContinuation: true,
136-
isBuiltInIdentifierAllowed: false);
129+
static const typeReferenceContinuation =
130+
const TypeReferenceIdentifierContext.continuation();
137131

138132
/// Identifier is a name being declared by a top level variable declaration.
139133
static const topLevelVariableDeclaration = const IdentifierContext(

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ class TypeReferenceIdentifierContext extends IdentifierContext {
7575
isBuiltInIdentifierAllowed: false,
7676
recoveryTemplate: fasta.templateExpectedType);
7777

78+
const TypeReferenceIdentifierContext.continuation()
79+
: super('typeReferenceContinuation',
80+
isContinuation: true, isBuiltInIdentifierAllowed: false);
81+
82+
const TypeReferenceIdentifierContext.prefixed()
83+
: super('prefixedTypeReference',
84+
isScopeReference: true,
85+
isBuiltInIdentifierAllowed: true,
86+
recoveryTemplate: fasta.templateExpectedType);
87+
7888
@override
7989
Token ensureIdentifier(Token token, Parser parser) {
8090
Token next = token.next;
@@ -109,8 +119,10 @@ class TypeReferenceIdentifierContext extends IdentifierContext {
109119
if (optional("void", next)) {
110120
parser.reportRecoverableError(next, fasta.messageInvalidVoid);
111121
} else if (next.type.isBuiltIn) {
112-
parser.reportRecoverableErrorWithToken(
113-
next, fasta.templateBuiltInIdentifierAsType);
122+
if (!isBuiltInIdentifierAllowed) {
123+
parser.reportRecoverableErrorWithToken(
124+
next, fasta.templateBuiltInIdentifierAsType);
125+
}
114126
} else {
115127
parser.reportRecoverableErrorWithToken(
116128
next, fasta.templateExpectedType);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,6 @@ class Parser {
20082008
followingValues = [';', '=', ','];
20092009
} else if (context == IdentifierContext.typedefDeclaration) {
20102010
followingValues = ['(', '<', ';'];
2011-
} else if (context == IdentifierContext.typeReferenceContinuation) {
2012-
followingValues = ['>', ')', ']', '}', ',', ';'];
20132011
} else if (context == IdentifierContext.typeVariableDeclaration) {
20142012
followingValues = ['<', '>', ';', '}'];
20152013
} else {

0 commit comments

Comments
 (0)