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

Commit 16937cf

Browse files
author
Dart CI
committed
Version 2.10.0-108.0.dev
Merge commit '69b194e88f99e85a653d7b71e4883adda72c7c5c' into 'dev'
2 parents 2e838b7 + 69b194e commit 16937cf

File tree

58 files changed

+2826
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2826
-238
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 130 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,33 @@ const MessageCode messageConstructorCyclic = const MessageCode(
15141514
tip:
15151515
r"""Try to have all constructors eventually redirect to a non-redirecting constructor.""");
15161516

1517+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1518+
const Template<Message Function(String name)>
1519+
templateConstructorInitializeSameInstanceVariableSeveralTimes =
1520+
const Template<Message Function(String name)>(
1521+
messageTemplate:
1522+
r"""'#name' was already initialized by this constructor.""",
1523+
withArguments:
1524+
_withArgumentsConstructorInitializeSameInstanceVariableSeveralTimes);
1525+
1526+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1527+
const Code<Message Function(String name)>
1528+
codeConstructorInitializeSameInstanceVariableSeveralTimes =
1529+
const Code<Message Function(String name)>(
1530+
"ConstructorInitializeSameInstanceVariableSeveralTimes",
1531+
templateConstructorInitializeSameInstanceVariableSeveralTimes,
1532+
analyzerCodes: <String>["FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS"]);
1533+
1534+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1535+
Message _withArgumentsConstructorInitializeSameInstanceVariableSeveralTimes(
1536+
String name) {
1537+
if (name.isEmpty) throw 'No name provided';
1538+
name = demangleMixinApplicationName(name);
1539+
return new Message(codeConstructorInitializeSameInstanceVariableSeveralTimes,
1540+
message: """'${name}' was already initialized by this constructor.""",
1541+
arguments: {'name': name});
1542+
}
1543+
15171544
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
15181545
const Template<Message Function(String name)> templateConstructorNotFound =
15191546
const Template<Message Function(String name)>(
@@ -3727,6 +3754,60 @@ Message _withArgumentsFfiStructGeneric(String name) {
37273754
arguments: {'name': name});
37283755
}
37293756

3757+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3758+
const Template<
3759+
Message Function(
3760+
String
3761+
name)> templateFieldAlreadyInitializedAtDeclaration = const Template<
3762+
Message Function(String name)>(
3763+
messageTemplate:
3764+
r"""'#name' is a final instance variable that was initialized at the declaration.""",
3765+
withArguments: _withArgumentsFieldAlreadyInitializedAtDeclaration);
3766+
3767+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3768+
const Code<Message Function(String name)>
3769+
codeFieldAlreadyInitializedAtDeclaration =
3770+
const Code<Message Function(String name)>(
3771+
"FieldAlreadyInitializedAtDeclaration",
3772+
templateFieldAlreadyInitializedAtDeclaration,
3773+
analyzerCodes: <String>[
3774+
"FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION"
3775+
]);
3776+
3777+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3778+
Message _withArgumentsFieldAlreadyInitializedAtDeclaration(String name) {
3779+
if (name.isEmpty) throw 'No name provided';
3780+
name = demangleMixinApplicationName(name);
3781+
return new Message(codeFieldAlreadyInitializedAtDeclaration,
3782+
message:
3783+
"""'${name}' is a final instance variable that was initialized at the declaration.""",
3784+
arguments: {'name': name});
3785+
}
3786+
3787+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3788+
const Template<Message Function(String name)>
3789+
templateFieldAlreadyInitializedAtDeclarationCause =
3790+
const Template<Message Function(String name)>(
3791+
messageTemplate: r"""'#name' was initialized here.""",
3792+
withArguments: _withArgumentsFieldAlreadyInitializedAtDeclarationCause);
3793+
3794+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3795+
const Code<Message Function(String name)>
3796+
codeFieldAlreadyInitializedAtDeclarationCause =
3797+
const Code<Message Function(String name)>(
3798+
"FieldAlreadyInitializedAtDeclarationCause",
3799+
templateFieldAlreadyInitializedAtDeclarationCause,
3800+
severity: Severity.context);
3801+
3802+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3803+
Message _withArgumentsFieldAlreadyInitializedAtDeclarationCause(String name) {
3804+
if (name.isEmpty) throw 'No name provided';
3805+
name = demangleMixinApplicationName(name);
3806+
return new Message(codeFieldAlreadyInitializedAtDeclarationCause,
3807+
message: """'${name}' was initialized here.""",
3808+
arguments: {'name': name});
3809+
}
3810+
37303811
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
37313812
const Code<Null> codeFieldInitializedOutsideDeclaringClass =
37323813
messageFieldInitializedOutsideDeclaringClass;
@@ -3870,58 +3951,6 @@ Message _withArgumentsFinalFieldWithoutInitializer(String name) {
38703951
arguments: {'name': name});
38713952
}
38723953

3873-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3874-
const Template<Message Function(String name)>
3875-
templateFinalInstanceVariableAlreadyInitialized =
3876-
const Template<Message Function(String name)>(
3877-
messageTemplate:
3878-
r"""'#name' is a final instance variable that has already been initialized.""",
3879-
withArguments: _withArgumentsFinalInstanceVariableAlreadyInitialized);
3880-
3881-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3882-
const Code<Message Function(String name)>
3883-
codeFinalInstanceVariableAlreadyInitialized =
3884-
const Code<Message Function(String name)>(
3885-
"FinalInstanceVariableAlreadyInitialized",
3886-
templateFinalInstanceVariableAlreadyInitialized,
3887-
analyzerCodes: <String>["FINAL_INITIALIZED_MULTIPLE_TIMES"]);
3888-
3889-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3890-
Message _withArgumentsFinalInstanceVariableAlreadyInitialized(String name) {
3891-
if (name.isEmpty) throw 'No name provided';
3892-
name = demangleMixinApplicationName(name);
3893-
return new Message(codeFinalInstanceVariableAlreadyInitialized,
3894-
message:
3895-
"""'${name}' is a final instance variable that has already been initialized.""",
3896-
arguments: {'name': name});
3897-
}
3898-
3899-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3900-
const Template<Message Function(String name)>
3901-
templateFinalInstanceVariableAlreadyInitializedCause =
3902-
const Template<Message Function(String name)>(
3903-
messageTemplate: r"""'#name' was initialized here.""",
3904-
withArguments:
3905-
_withArgumentsFinalInstanceVariableAlreadyInitializedCause);
3906-
3907-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3908-
const Code<Message Function(String name)>
3909-
codeFinalInstanceVariableAlreadyInitializedCause =
3910-
const Code<Message Function(String name)>(
3911-
"FinalInstanceVariableAlreadyInitializedCause",
3912-
templateFinalInstanceVariableAlreadyInitializedCause,
3913-
severity: Severity.context);
3914-
3915-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3916-
Message _withArgumentsFinalInstanceVariableAlreadyInitializedCause(
3917-
String name) {
3918-
if (name.isEmpty) throw 'No name provided';
3919-
name = demangleMixinApplicationName(name);
3920-
return new Message(codeFinalInstanceVariableAlreadyInitializedCause,
3921-
message: """'${name}' was initialized here.""",
3922-
arguments: {'name': name});
3923-
}
3924-
39253954
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
39263955
const Code<Null> codeForInLoopExactlyOneVariable =
39273956
messageForInLoopExactlyOneVariable;
@@ -6128,14 +6157,14 @@ Message _withArgumentsModifierOutOfOrder(String string, String string2) {
61286157
}
61296158

61306159
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6131-
const Code<Null> codeMoreThanOneSuperOrThisInitializer =
6132-
messageMoreThanOneSuperOrThisInitializer;
6160+
const Code<Null> codeMoreThanOneSuperInitializer =
6161+
messageMoreThanOneSuperInitializer;
61336162

61346163
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6135-
const MessageCode messageMoreThanOneSuperOrThisInitializer = const MessageCode(
6136-
"MoreThanOneSuperOrThisInitializer",
6137-
analyzerCodes: <String>["SUPER_IN_REDIRECTING_CONSTRUCTOR"],
6138-
message: r"""Can't have more than one 'super' or 'this' initializer.""");
6164+
const MessageCode messageMoreThanOneSuperInitializer = const MessageCode(
6165+
"MoreThanOneSuperInitializer",
6166+
analyzerCodes: <String>["MULTIPLE_SUPER_INITIALIZERS"],
6167+
message: r"""Can't have more than one 'super' initializer.""");
61396168

61406169
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
61416170
const Code<Null> codeMultipleExtends = messageMultipleExtends;
@@ -6801,6 +6830,15 @@ Message _withArgumentsNullableMixinError(String name) {
68016830
arguments: {'name': name});
68026831
}
68036832

6833+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6834+
const Code<Null> codeNullableSpreadError = messageNullableSpreadError;
6835+
6836+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6837+
const MessageCode messageNullableSpreadError = const MessageCode(
6838+
"NullableSpreadError",
6839+
message:
6840+
r"""An expression whose value can be 'null' must be null-checked before it can be dereferenced.""");
6841+
68046842
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
68056843
const Template<Message Function(String name)> templateNullableSuperclassError =
68066844
const Template<Message Function(String name)>(
@@ -7605,6 +7643,17 @@ const MessageCode messagePrivateNamedParameter = const MessageCode(
76057643
analyzerCodes: <String>["PRIVATE_OPTIONAL_PARAMETER"],
76067644
message: r"""An optional named parameter can't start with '_'.""");
76077645

7646+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7647+
const Code<Null> codeRedirectingConstructorWithAnotherInitializer =
7648+
messageRedirectingConstructorWithAnotherInitializer;
7649+
7650+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7651+
const MessageCode messageRedirectingConstructorWithAnotherInitializer =
7652+
const MessageCode("RedirectingConstructorWithAnotherInitializer",
7653+
analyzerCodes: <String>["FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR"],
7654+
message:
7655+
r"""A redirecting constructor can't have other initializers.""");
7656+
76087657
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
76097658
const Code<Null> codeRedirectingConstructorWithBody =
76107659
messageRedirectingConstructorWithBody;
@@ -7617,6 +7666,29 @@ const MessageCode messageRedirectingConstructorWithBody = const MessageCode(
76177666
tip:
76187667
r"""Try removing the body, or not making this a redirecting constructor.""");
76197668

7669+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7670+
const Code<Null> codeRedirectingConstructorWithMultipleRedirectInitializers =
7671+
messageRedirectingConstructorWithMultipleRedirectInitializers;
7672+
7673+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7674+
const MessageCode
7675+
messageRedirectingConstructorWithMultipleRedirectInitializers =
7676+
const MessageCode("RedirectingConstructorWithMultipleRedirectInitializers",
7677+
analyzerCodes: <String>["MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS"],
7678+
message:
7679+
r"""A redirecting constructor can't have more than one redirection.""");
7680+
7681+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7682+
const Code<Null> codeRedirectingConstructorWithSuperInitializer =
7683+
messageRedirectingConstructorWithSuperInitializer;
7684+
7685+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7686+
const MessageCode messageRedirectingConstructorWithSuperInitializer =
7687+
const MessageCode("RedirectingConstructorWithSuperInitializer",
7688+
analyzerCodes: <String>["SUPER_IN_REDIRECTING_CONSTRUCTOR"],
7689+
message:
7690+
r"""A redirecting constructor can't have a 'super' initializer.""");
7691+
76207692
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
76217693
const Code<Null> codeRedirectionInNonFactory = messageRedirectionInNonFactory;
76227694

@@ -8412,15 +8484,6 @@ const MessageCode messageThisAsIdentifier = const MessageCode(
84128484
analyzerCodes: <String>["INVALID_REFERENCE_TO_THIS"],
84138485
message: r"""Expected identifier, but got 'this'.""");
84148486

8415-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8416-
const Code<Null> codeThisInitializerNotAlone = messageThisInitializerNotAlone;
8417-
8418-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8419-
const MessageCode messageThisInitializerNotAlone = const MessageCode(
8420-
"ThisInitializerNotAlone",
8421-
analyzerCodes: <String>["FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR"],
8422-
message: r"""Can't have other initializers together with 'this'.""");
8423-
84248487
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
84258488
const Template<Message Function(String string)>
84268489
templateThisOrSuperAccessInFieldInitializer =

pkg/front_end/lib/src/fasta/builder/constructor_builder.dart

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import '../loader.dart' show Loader;
2424
import '../messages.dart'
2525
show
2626
Message,
27-
messageMoreThanOneSuperOrThisInitializer,
27+
messageMoreThanOneSuperInitializer,
28+
messageRedirectingConstructorWithAnotherInitializer,
29+
messageRedirectingConstructorWithMultipleRedirectInitializers,
30+
messageRedirectingConstructorWithSuperInitializer,
2831
messageSuperInitializerNotLast,
29-
messageThisInitializerNotAlone,
3032
noLength;
3133

3234
import '../source/source_library_builder.dart' show SourceLibraryBuilder;
@@ -68,8 +70,8 @@ abstract class ConstructorBuilder implements FunctionBuilder {
6870
/// The [Constructor] built by this builder.
6971
Constructor get constructor;
7072

71-
void injectInvalidInitializer(
72-
Message message, int charOffset, ExpressionGeneratorHelper helper);
73+
void injectInvalidInitializer(Message message, int charOffset, int length,
74+
ExpressionGeneratorHelper helper);
7375

7476
void addInitializer(
7577
Initializer initializer, ExpressionGeneratorHelper helper);
@@ -273,14 +275,14 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
273275
Member get member => constructor;
274276

275277
@override
276-
void injectInvalidInitializer(
277-
Message message, int charOffset, ExpressionGeneratorHelper helper) {
278+
void injectInvalidInitializer(Message message, int charOffset, int length,
279+
ExpressionGeneratorHelper helper) {
278280
List<Initializer> initializers = _constructor.initializers;
279281
Initializer lastInitializer = initializers.removeLast();
280282
assert(lastInitializer == superInitializer ||
281283
lastInitializer == redirectingInitializer);
282284
Initializer error = helper.buildInvalidInitializer(
283-
helper.buildProblem(message, charOffset, noLength));
285+
helper.buildProblem(message, charOffset, length));
284286
initializers.add(error..parent = _constructor);
285287
initializers.add(lastInitializer);
286288
}
@@ -290,32 +292,64 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
290292
Initializer initializer, ExpressionGeneratorHelper helper) {
291293
List<Initializer> initializers = _constructor.initializers;
292294
if (initializer is SuperInitializer) {
293-
if (superInitializer != null || redirectingInitializer != null) {
294-
injectInvalidInitializer(messageMoreThanOneSuperOrThisInitializer,
295-
initializer.fileOffset, helper);
295+
if (superInitializer != null) {
296+
injectInvalidInitializer(messageMoreThanOneSuperInitializer,
297+
initializer.fileOffset, "super".length, helper);
298+
} else if (redirectingInitializer != null) {
299+
injectInvalidInitializer(
300+
messageRedirectingConstructorWithSuperInitializer,
301+
initializer.fileOffset,
302+
"super".length,
303+
helper);
296304
} else {
297305
initializers.add(initializer..parent = _constructor);
298306
superInitializer = initializer;
299307
}
300308
} else if (initializer is RedirectingInitializer) {
301-
if (superInitializer != null || redirectingInitializer != null) {
302-
injectInvalidInitializer(messageMoreThanOneSuperOrThisInitializer,
303-
initializer.fileOffset, helper);
304-
} else if (_constructor.initializers.isNotEmpty) {
305-
Initializer first = _constructor.initializers.first;
306-
Initializer error = helper.buildInvalidInitializer(helper.buildProblem(
307-
messageThisInitializerNotAlone, first.fileOffset, noLength));
308-
initializers.add(error..parent = _constructor);
309+
if (superInitializer != null) {
310+
// Point to the existing super initializer.
311+
injectInvalidInitializer(
312+
messageRedirectingConstructorWithSuperInitializer,
313+
superInitializer.fileOffset,
314+
"super".length,
315+
helper);
316+
} else if (redirectingInitializer != null) {
317+
injectInvalidInitializer(
318+
messageRedirectingConstructorWithMultipleRedirectInitializers,
319+
initializer.fileOffset,
320+
noLength,
321+
helper);
322+
} else if (initializers.isNotEmpty) {
323+
// Error on all previous ones.
324+
for (int i = 0; i < initializers.length; i++) {
325+
Initializer initializer = initializers[i];
326+
int length = noLength;
327+
if (initializer is AssertInitializer) length = "assert".length;
328+
Initializer error = helper.buildInvalidInitializer(
329+
helper.buildProblem(
330+
messageRedirectingConstructorWithAnotherInitializer,
331+
initializer.fileOffset,
332+
length));
333+
error.parent = _constructor;
334+
initializers[i] = error;
335+
}
336+
initializers.add(initializer..parent = _constructor);
337+
redirectingInitializer = initializer;
309338
} else {
310339
initializers.add(initializer..parent = _constructor);
311340
redirectingInitializer = initializer;
312341
}
313342
} else if (redirectingInitializer != null) {
343+
int length = noLength;
344+
if (initializer is AssertInitializer) length = "assert".length;
314345
injectInvalidInitializer(
315-
messageThisInitializerNotAlone, initializer.fileOffset, helper);
346+
messageRedirectingConstructorWithAnotherInitializer,
347+
initializer.fileOffset,
348+
length,
349+
helper);
316350
} else if (superInitializer != null) {
317-
injectInvalidInitializer(
318-
messageSuperInitializerNotLast, superInitializer.fileOffset, helper);
351+
injectInvalidInitializer(messageSuperInitializerNotLast,
352+
initializer.fileOffset, noLength, helper);
319353
} else {
320354
initializers.add(initializer..parent = _constructor);
321355
}

0 commit comments

Comments
 (0)