Skip to content

Commit 64f2899

Browse files
FMorschelCommit Queue
authored andcommitted
[analyzer] Adds new message for INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR
Fixes: #61680 Change-Id: I3f5e0e722125a05bcc0f7ff4f9f785c584b7d94b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453360 Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 47cc314 commit 64f2899

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,9 @@ CompileTimeErrorCode.INVALID_OVERRIDE_SETTER:
10001000
CompileTimeErrorCode.INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR:
10011001
status: noFix
10021002
since: 2.17
1003+
CompileTimeErrorCode.INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR_TEAROFF:
1004+
status: noFix
1005+
since: 2.17
10031006
CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS:
10041007
status: noFix
10051008
CompileTimeErrorCode.INVALID_SUPER_FORMAL_PARAMETER_LOCATION:

pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ const List<DiagnosticCode> diagnosticCodeValues = [
325325
CompileTimeErrorCode.invalidOverride,
326326
CompileTimeErrorCode.invalidOverrideSetter,
327327
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructor,
328+
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructorTearoff,
328329
CompileTimeErrorCode.invalidReferenceToThis,
329330
CompileTimeErrorCode.invalidSuperFormalParameterLocation,
330331
CompileTimeErrorCode.invalidTypeArgumentInConstList,

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4031,12 +4031,24 @@ class CompileTimeErrorCode extends DiagnosticCodeWithExpectedTypes {
40314031
static const CompileTimeErrorWithoutArguments
40324032
invalidReferenceToGenerativeEnumConstructor = CompileTimeErrorWithoutArguments(
40334033
'INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR',
4034-
"Generative enum constructors can only be used as targets of redirection.",
4034+
"Generative enum constructors can only be used to create an enum constant.",
40354035
correctionMessage: "Try using an enum value, or a factory constructor.",
40364036
hasPublishedDocs: true,
40374037
expectedTypes: [],
40384038
);
40394039

4040+
/// No parameters.
4041+
static const CompileTimeErrorWithoutArguments
4042+
invalidReferenceToGenerativeEnumConstructorTearoff =
4043+
CompileTimeErrorWithoutArguments(
4044+
'INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR',
4045+
"Generative enum constructors can't be torn off.",
4046+
correctionMessage: "Try using an enum value, or a factory constructor.",
4047+
hasPublishedDocs: true,
4048+
uniqueName: 'INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR_TEAROFF',
4049+
expectedTypes: [],
4050+
);
4051+
40404052
/// No parameters.
40414053
static const CompileTimeErrorWithoutArguments invalidReferenceToThis =
40424054
CompileTimeErrorWithoutArguments(

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,10 +3860,20 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
38603860
constructorElement.isGenerative &&
38613861
constructorElement.enclosingElement is EnumElement) {
38623862
if (_currentLibrary.featureSet.isEnabled(Feature.enhanced_enums)) {
3863-
diagnosticReporter.atNode(
3864-
node,
3865-
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructor,
3866-
);
3863+
if (node.parent case ConstructorReference(
3864+
:var parent,
3865+
) when parent is! InstanceCreationExpression) {
3866+
diagnosticReporter.atNode(
3867+
node,
3868+
CompileTimeErrorCode
3869+
.invalidReferenceToGenerativeEnumConstructorTearoff,
3870+
);
3871+
} else {
3872+
diagnosticReporter.atNode(
3873+
node,
3874+
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructor,
3875+
);
3876+
}
38673877
} else {
38683878
diagnosticReporter.atNode(node, CompileTimeErrorCode.instantiateEnum);
38693879
}

pkg/analyzer/messages.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9079,7 +9079,7 @@ CompileTimeErrorCode:
90799079
hasPublishedDocs: true
90809080
INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR:
90819081
parameters: none
9082-
problemMessage: Generative enum constructors can only be used as targets of redirection.
9082+
problemMessage: Generative enum constructors can only be used to create an enum constant.
90839083
correctionMessage: Try using an enum value, or a factory constructor.
90849084
hasPublishedDocs: true
90859085
documentation: |-
@@ -9134,6 +9134,12 @@ CompileTimeErrorCode:
91349134

91359135
E f() => E.c(2);
91369136
```
9137+
INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR_TEAROFF:
9138+
sharedName: INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR
9139+
parameters: none
9140+
problemMessage: Generative enum constructors can't be torn off.
9141+
correctionMessage: Try using an enum value, or a factory constructor.
9142+
hasPublishedDocs: true
91379143
INVALID_REFERENCE_TO_THIS:
91389144
parameters: none
91399145
problemMessage: "Invalid reference to 'this' expression."

pkg/analyzer/test/src/diagnostics/invalid_reference_to_generative_enum_constructor_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void f() {
6262
''',
6363
[
6464
error(
65-
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructor,
65+
CompileTimeErrorCode
66+
.invalidReferenceToGenerativeEnumConstructorTearoff,
6667
58,
6768
7,
6869
),
@@ -142,7 +143,8 @@ void f() {
142143
''',
143144
[
144145
error(
145-
CompileTimeErrorCode.invalidReferenceToGenerativeEnumConstructor,
146+
CompileTimeErrorCode
147+
.invalidReferenceToGenerativeEnumConstructorTearoff,
146148
29,
147149
5,
148150
),

0 commit comments

Comments
 (0)