Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fee615c

Browse files
danrubelcommit-bot@chromium.org
danrubel
authored and
commit-bot@chromium.org
committed
consolidate multiple modifier error codes
This consolidates the following error codes into MODIFIER_OUT_OF_ORDER * COVARIANT_AFTER_VAR * EXTERNAL_AFTER_CONST * EXTERNAL_AFTER_FACTORY * EXTERNAL_AFTER_STATIC * STATIC_AFTER_CONST * STATIC_AFTER_FINAL * STATIC_AFTER_VAR Change-Id: I3f8c41bacc65ebc5d9255806cbee89cddb5ffeb1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103880 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Auto-Submit: Dan Rubel <danrubel@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 6aee4f3 commit fee615c

File tree

8 files changed

+48
-211
lines changed

8 files changed

+48
-211
lines changed

pkg/analyzer/lib/src/dart/error/syntactic_errors.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ParserErrorCode extends ErrorCode {
109109
// TODO(danrubel): Remove this unused error code
110110
static const ParserErrorCode COVARIANT_AFTER_FINAL = _MODIFIER_OUT_OF_ORDER;
111111

112-
static const ParserErrorCode COVARIANT_AFTER_VAR = _COVARIANT_AFTER_VAR;
112+
static const ParserErrorCode COVARIANT_AFTER_VAR = _MODIFIER_OUT_OF_ORDER;
113113

114114
static const ParserErrorCode COVARIANT_AND_STATIC = _COVARIANT_AND_STATIC;
115115

@@ -204,11 +204,11 @@ class ParserErrorCode extends ErrorCode {
204204
static const ParserErrorCode EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE =
205205
_EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE;
206206

207-
static const ParserErrorCode EXTERNAL_AFTER_CONST = _EXTERNAL_AFTER_CONST;
207+
static const ParserErrorCode EXTERNAL_AFTER_CONST = _MODIFIER_OUT_OF_ORDER;
208208

209-
static const ParserErrorCode EXTERNAL_AFTER_FACTORY = _EXTERNAL_AFTER_FACTORY;
209+
static const ParserErrorCode EXTERNAL_AFTER_FACTORY = _MODIFIER_OUT_OF_ORDER;
210210

211-
static const ParserErrorCode EXTERNAL_AFTER_STATIC = _EXTERNAL_AFTER_STATIC;
211+
static const ParserErrorCode EXTERNAL_AFTER_STATIC = _MODIFIER_OUT_OF_ORDER;
212212

213213
static const ParserErrorCode EXTERNAL_CLASS = _EXTERNAL_CLASS;
214214

@@ -663,11 +663,11 @@ class ParserErrorCode extends ErrorCode {
663663

664664
static const ParserErrorCode STACK_OVERFLOW = _STACK_OVERFLOW;
665665

666-
static const ParserErrorCode STATIC_AFTER_CONST = _STATIC_AFTER_CONST;
666+
static const ParserErrorCode STATIC_AFTER_CONST = _MODIFIER_OUT_OF_ORDER;
667667

668-
static const ParserErrorCode STATIC_AFTER_FINAL = _STATIC_AFTER_FINAL;
668+
static const ParserErrorCode STATIC_AFTER_FINAL = _MODIFIER_OUT_OF_ORDER;
669669

670-
static const ParserErrorCode STATIC_AFTER_VAR = _STATIC_AFTER_VAR;
670+
static const ParserErrorCode STATIC_AFTER_VAR = _MODIFIER_OUT_OF_ORDER;
671671

672672
static const ParserErrorCode STATIC_CONSTRUCTOR = _STATIC_CONSTRUCTOR;
673673

pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
1515
_EXTERNAL_ENUM,
1616
_PREFIX_AFTER_COMBINATOR,
1717
_TYPEDEF_IN_CLASS,
18-
_COVARIANT_AFTER_VAR,
18+
_EXPECTED_BODY,
1919
_INVALID_AWAIT_IN_FOR,
2020
_IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
2121
_WITH_BEFORE_EXTENDS,
@@ -25,9 +25,9 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
2525
_SWITCH_HAS_MULTIPLE_DEFAULT_CASES,
2626
_SWITCH_HAS_CASE_AFTER_DEFAULT_CASE,
2727
_STATIC_OPERATOR,
28-
_STATIC_AFTER_VAR,
29-
_STATIC_AFTER_FINAL,
30-
_STATIC_AFTER_CONST,
28+
_INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER,
29+
_STACK_OVERFLOW,
30+
_MISSING_CATCH_OR_FINALLY,
3131
_REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR,
3232
_REDIRECTING_CONSTRUCTOR_WITH_BODY,
3333
_NATIVE_CLAUSE_SHOULD_BE_ANNOTATION,
@@ -53,9 +53,9 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
5353
_IMPLEMENTS_BEFORE_ON,
5454
_IMPLEMENTS_BEFORE_EXTENDS,
5555
_ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE,
56-
_EXTERNAL_AFTER_CONST,
57-
_EXTERNAL_AFTER_FACTORY,
58-
_EXTERNAL_AFTER_STATIC,
56+
_EXPECTED_ELSE_OR_COMMA,
57+
_INVALID_SUPER_IN_INITIALIZER,
58+
_EXPERIMENT_NOT_ENABLED,
5959
_EXTERNAL_METHOD_WITH_BODY,
6060
_EXTERNAL_FIELD,
6161
_ABSTRACT_CLASS_MEMBER,
@@ -97,13 +97,6 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
9797
_EXTERNAL_CONSTRUCTOR_WITH_BODY,
9898
_FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS,
9999
_VAR_AND_TYPE,
100-
_INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER,
101-
_STACK_OVERFLOW,
102-
_MISSING_CATCH_OR_FINALLY,
103-
_EXPERIMENT_NOT_ENABLED,
104-
_EXPECTED_ELSE_OR_COMMA,
105-
_INVALID_SUPER_IN_INITIALIZER,
106-
_EXPECTED_BODY,
107100
];
108101

109102
const ParserErrorCode _ABSTRACT_CLASS_MEMBER = const ParserErrorCode(
@@ -175,11 +168,6 @@ const ParserErrorCode _CONTINUE_WITHOUT_LABEL_IN_CASE = const ParserErrorCode(
175168
correction:
176169
"Try adding a label associated with one of the case clauses to the continue statement.");
177170

178-
const ParserErrorCode _COVARIANT_AFTER_VAR = const ParserErrorCode(
179-
'COVARIANT_AFTER_VAR',
180-
r"The modifier 'covariant' should be before the modifier 'var'.",
181-
correction: "Try re-ordering the modifiers.");
182-
183171
const ParserErrorCode _COVARIANT_AND_STATIC = const ParserErrorCode(
184172
'COVARIANT_AND_STATIC',
185173
r"Members can't be declared to be both 'covariant' and 'static'.",
@@ -250,21 +238,6 @@ const ParserErrorCode _EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE =
250238
correction:
251239
"Try moving the export directives before the part directives.");
252240

253-
const ParserErrorCode _EXTERNAL_AFTER_CONST = const ParserErrorCode(
254-
'EXTERNAL_AFTER_CONST',
255-
r"The modifier 'external' should be before the modifier 'const'.",
256-
correction: "Try re-ordering the modifiers.");
257-
258-
const ParserErrorCode _EXTERNAL_AFTER_FACTORY = const ParserErrorCode(
259-
'EXTERNAL_AFTER_FACTORY',
260-
r"The modifier 'external' should be before the modifier 'factory'.",
261-
correction: "Try re-ordering the modifiers.");
262-
263-
const ParserErrorCode _EXTERNAL_AFTER_STATIC = const ParserErrorCode(
264-
'EXTERNAL_AFTER_STATIC',
265-
r"The modifier 'external' should be before the modifier 'static'.",
266-
correction: "Try re-ordering the modifiers.");
267-
268241
const ParserErrorCode _EXTERNAL_CLASS = const ParserErrorCode(
269242
'EXTERNAL_CLASS', r"Classes can't be declared to be 'external'.",
270243
correction: "Try removing the keyword 'external'.");
@@ -497,21 +470,6 @@ const ParserErrorCode _STACK_OVERFLOW = const ParserErrorCode('STACK_OVERFLOW',
497470
r"The file has too many nested expressions or statements.",
498471
correction: "Try simplifying the code.");
499472

500-
const ParserErrorCode _STATIC_AFTER_CONST = const ParserErrorCode(
501-
'STATIC_AFTER_CONST',
502-
r"The modifier 'static' should be before the modifier 'const'.",
503-
correction: "Try re-ordering the modifiers.");
504-
505-
const ParserErrorCode _STATIC_AFTER_FINAL = const ParserErrorCode(
506-
'STATIC_AFTER_FINAL',
507-
r"The modifier 'static' should be before the modifier 'final'.",
508-
correction: "Try re-ordering the modifiers.");
509-
510-
const ParserErrorCode _STATIC_AFTER_VAR = const ParserErrorCode(
511-
'STATIC_AFTER_VAR',
512-
r"The modifier 'static' should be before the modifier 'var'.",
513-
correction: "Try re-ordering the modifiers.");
514-
515473
const ParserErrorCode _STATIC_CONSTRUCTOR = const ParserErrorCode(
516474
'STATIC_CONSTRUCTOR', r"Constructors can't be static.",
517475
correction: "Try removing the keyword 'static'.");

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3253,7 +3253,7 @@ class Foo {
32533253
ClassMember member = parser.parseClassMember('C');
32543254
expectNotNullIfNoErrors(member);
32553255
listener.assertErrors(
3256-
[expectedError(ParserErrorCode.EXTERNAL_AFTER_FACTORY, 8, 8)]);
3256+
[expectedError(ParserErrorCode.MODIFIER_OUT_OF_ORDER, 8, 8)]);
32573257
}
32583258

32593259
void test_externalAfterStatic() {

pkg/analyzer/test/src/task/options_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ class ErrorCodeValuesTest {
240240
declaredNames.remove('CONST_AND_COVARIANT');
241241
declaredNames.remove('CONST_AND_VAR');
242242
declaredNames.remove('COVARIANT_AFTER_FINAL');
243+
declaredNames.remove('COVARIANT_AFTER_VAR');
244+
declaredNames.remove('EXTERNAL_AFTER_CONST');
245+
declaredNames.remove('EXTERNAL_AFTER_FACTORY');
246+
declaredNames.remove('EXTERNAL_AFTER_STATIC');
243247
declaredNames.remove('MISSING_CLASS_BODY');
248+
declaredNames.remove('STATIC_AFTER_CONST');
249+
declaredNames.remove('STATIC_AFTER_FINAL');
250+
declaredNames.remove('STATIC_AFTER_VAR');
244251
}
245252

246253
// Assert that all remaining declared names are in errorCodeValues

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

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,17 +1942,6 @@ Message _withArgumentsCouldNotParseUri(String string, String string2) {
19421942
${string2}.""", arguments: {'string': string, 'string2': string2});
19431943
}
19441944

1945-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1946-
const Code<Null> codeCovariantAfterVar = messageCovariantAfterVar;
1947-
1948-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1949-
const MessageCode messageCovariantAfterVar = const MessageCode(
1950-
"CovariantAfterVar",
1951-
index: 8,
1952-
message:
1953-
r"""The modifier 'covariant' should be before the modifier 'var'.""",
1954-
tip: r"""Try re-ordering the modifiers.""");
1955-
19561945
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
19571946
const Code<Null> codeCovariantAndStatic = messageCovariantAndStatic;
19581947

@@ -2974,7 +2963,7 @@ const Template<Message Function(String string)>
29742963
const Code<Message Function(String string)> codeExpectedClassOrMixinBody =
29752964
const Code<Message Function(String string)>(
29762965
"ExpectedClassOrMixinBody", templateExpectedClassOrMixinBody,
2977-
index: 96);
2966+
index: 8);
29782967

29792968
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
29802969
Message _withArgumentsExpectedClassOrMixinBody(String string) {
@@ -3011,7 +3000,7 @@ const Code<Null> codeExpectedElseOrComma = messageExpectedElseOrComma;
30113000
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
30123001
const MessageCode messageExpectedElseOrComma = const MessageCode(
30133002
"ExpectedElseOrComma",
3014-
index: 94,
3003+
index: 46,
30153004
message: r"""Expected 'else' or comma.""");
30163005

30173006
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3224,7 +3213,7 @@ const Template<
32243213
const Code<Message Function(String string)> codeExperimentNotEnabled =
32253214
const Code<Message Function(String string)>(
32263215
"ExperimentNotEnabled", templateExperimentNotEnabled,
3227-
index: 93);
3216+
index: 48);
32283217

32293218
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
32303219
Message _withArgumentsExperimentNotEnabled(String string) {
@@ -3326,39 +3315,6 @@ Message _withArgumentsExtendingRestricted(String name) {
33263315
arguments: {'name': name});
33273316
}
33283317

3329-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3330-
const Code<Null> codeExternalAfterConst = messageExternalAfterConst;
3331-
3332-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3333-
const MessageCode messageExternalAfterConst = const MessageCode(
3334-
"ExternalAfterConst",
3335-
index: 46,
3336-
message:
3337-
r"""The modifier 'external' should be before the modifier 'const'.""",
3338-
tip: r"""Try re-ordering the modifiers.""");
3339-
3340-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3341-
const Code<Null> codeExternalAfterFactory = messageExternalAfterFactory;
3342-
3343-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3344-
const MessageCode messageExternalAfterFactory = const MessageCode(
3345-
"ExternalAfterFactory",
3346-
index: 47,
3347-
message:
3348-
r"""The modifier 'external' should be before the modifier 'factory'.""",
3349-
tip: r"""Try re-ordering the modifiers.""");
3350-
3351-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3352-
const Code<Null> codeExternalAfterStatic = messageExternalAfterStatic;
3353-
3354-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3355-
const MessageCode messageExternalAfterStatic = const MessageCode(
3356-
"ExternalAfterStatic",
3357-
index: 48,
3358-
message:
3359-
r"""The modifier 'external' should be before the modifier 'static'.""",
3360-
tip: r"""Try re-ordering the modifiers.""");
3361-
33623318
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
33633319
const Code<Null> codeExternalClass = messageExternalClass;
33643320

@@ -6315,7 +6271,7 @@ const Code<Null> codeInvalidSuperInInitializer =
63156271
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
63166272
const MessageCode messageInvalidSuperInInitializer = const MessageCode(
63176273
"InvalidSuperInInitializer",
6318-
index: 95,
6274+
index: 47,
63196275
message:
63206276
r"""Can only use 'super' in an initializer for calling the superclass constructor (e.g. 'super()' or 'super.namedConstructor()')""");
63216277

@@ -7388,7 +7344,7 @@ const Code<Null> codeOnlyTry = messageOnlyTry;
73887344

73897345
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
73907346
const MessageCode messageOnlyTry = const MessageCode("OnlyTry",
7391-
index: 92,
7347+
index: 20,
73927348
message:
73937349
r"""A try block must be followed by an 'on', 'catch', or 'finally' clause.""",
73947350
tip:
@@ -8739,41 +8695,10 @@ const Code<Null> codeStackOverflow = messageStackOverflow;
87398695

87408696
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
87418697
const MessageCode messageStackOverflow = const MessageCode("StackOverflow",
8742-
index: 91,
8698+
index: 19,
87438699
message: r"""The file has too many nested expressions or statements.""",
87448700
tip: r"""Try simplifying the code.""");
87458701

8746-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8747-
const Code<Null> codeStaticAfterConst = messageStaticAfterConst;
8748-
8749-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8750-
const MessageCode messageStaticAfterConst = const MessageCode(
8751-
"StaticAfterConst",
8752-
index: 20,
8753-
message:
8754-
r"""The modifier 'static' should be before the modifier 'const'.""",
8755-
tip: r"""Try re-ordering the modifiers.""");
8756-
8757-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8758-
const Code<Null> codeStaticAfterFinal = messageStaticAfterFinal;
8759-
8760-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8761-
const MessageCode messageStaticAfterFinal = const MessageCode(
8762-
"StaticAfterFinal",
8763-
index: 19,
8764-
message:
8765-
r"""The modifier 'static' should be before the modifier 'final'.""",
8766-
tip: r"""Try re-ordering the modifiers.""");
8767-
8768-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8769-
const Code<Null> codeStaticAfterVar = messageStaticAfterVar;
8770-
8771-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8772-
const MessageCode messageStaticAfterVar = const MessageCode("StaticAfterVar",
8773-
index: 18,
8774-
message: r"""The modifier 'static' should be before the modifier 'var'.""",
8775-
tip: r"""Try re-ordering the modifiers.""");
8776-
87778702
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
87788703
const Code<Null> codeStaticAndInstanceConflict =
87798704
messageStaticAndInstanceConflict;
@@ -8847,7 +8772,7 @@ const Code<Null> codeSuperNullAware = messageSuperNullAware;
88478772

88488773
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
88498774
const MessageCode messageSuperNullAware = const MessageCode("SuperNullAware",
8850-
index: 90,
8775+
index: 18,
88518776
message:
88528777
r"""The operator '?.' cannot be used with 'super' because 'super' cannot be null.""",
88538778
tip: r"""Try replacing '?.' with '.'""");

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class ModifierRecoveryContext {
271271
covariantToken = next;
272272

273273
if (varToken != null) {
274-
parser.reportRecoverableError(next, fasta.messageCovariantAfterVar);
274+
reportModifierOutOfOrder(next, varToken.lexeme);
275275
} else if (finalToken != null) {
276276
reportModifierOutOfOrder(next, finalToken.lexeme);
277277
} else if (lateToken != null) {
@@ -303,11 +303,11 @@ class ModifierRecoveryContext {
303303
externalToken = next;
304304

305305
if (afterFactory) {
306-
parser.reportRecoverableError(next, fasta.messageExternalAfterFactory);
306+
reportModifierOutOfOrder(next, 'factory');
307307
} else if (constToken != null) {
308-
parser.reportRecoverableError(next, fasta.messageExternalAfterConst);
308+
reportModifierOutOfOrder(next, constToken.lexeme);
309309
} else if (staticToken != null) {
310-
parser.reportRecoverableError(next, fasta.messageExternalAfterStatic);
310+
reportModifierOutOfOrder(next, staticToken.lexeme);
311311
} else if (lateToken != null) {
312312
reportModifierOutOfOrder(next, lateToken.lexeme);
313313
}
@@ -399,11 +399,11 @@ class ModifierRecoveryContext {
399399
staticToken = next;
400400

401401
if (constToken != null) {
402-
parser.reportRecoverableError(next, fasta.messageStaticAfterConst);
402+
reportModifierOutOfOrder(next, constToken.lexeme);
403403
} else if (finalToken != null) {
404-
parser.reportRecoverableError(next, fasta.messageStaticAfterFinal);
404+
reportModifierOutOfOrder(next, finalToken.lexeme);
405405
} else if (varToken != null) {
406-
parser.reportRecoverableError(next, fasta.messageStaticAfterVar);
406+
reportModifierOutOfOrder(next, varToken.lexeme);
407407
} else if (lateToken != null) {
408408
reportModifierOutOfOrder(next, lateToken.lexeme);
409409
}

pkg/front_end/messages.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ ContinueOutsideOfLoop/script1: Fail
102102
ContinueWithoutLabelInCase/script1: Fail
103103
CouldNotParseUri/analyzerCode: Fail
104104
CouldNotParseUri/example: Fail
105-
CovariantAfterVar/script1: Fail
106105
CovariantAndStatic/script1: Fail
107106
CovariantAndStatic/script2: Fail
108107
CovariantMember/script1: Fail
@@ -360,7 +359,6 @@ SourceOutlineSummary/example: Fail
360359
SpreadMapEntryTypeMismatch/analyzerCode: Fail # There's no analyzer code for that error yet.
361360
SpreadTypeMismatch/analyzerCode: Fail # There's no analyzer code for that error yet.
362361
StackOverflow/example: Fail
363-
StaticAfterConst/script1: Fail
364362
SuperAsExpression/example: Fail
365363
SuperAsIdentifier/example: Fail
366364
SuperNullAware/example: Fail

0 commit comments

Comments
 (0)