Skip to content

Commit c912633

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Rename misleading error codes
In all three cases, the if the element in question were not a const we'd produce a different code, so "non-constant" is misleading. Change-Id: If04fb4a91815612b47dd1357806bdfc2b047841b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112700 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent e7b3d29 commit c912633

File tree

7 files changed

+65
-84
lines changed

7 files changed

+65
-84
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ const List<ErrorCode> errorCodeValues = const [
156156
CompileTimeErrorCode.GENERIC_FUNCTION_TYPED_PARAM_UNSUPPORTED,
157157
CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND,
158158
CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_TYPE_ARGUMENT,
159+
CompileTimeErrorCode.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
159160
CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS,
160161
CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
161162
CompileTimeErrorCode.IMPLEMENTS_NON_CLASS,
@@ -238,9 +239,6 @@ const List<ErrorCode> errorCodeValues = const [
238239
CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT,
239240
CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY,
240241
CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT,
241-
CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
242-
CompileTimeErrorCode.NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
243-
CompileTimeErrorCode.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
244242
// ignore: deprecated_member_use_from_same_package
245243
CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER,
246244
CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT,
@@ -287,7 +285,9 @@ const List<ErrorCode> errorCodeValues = const [
287285
CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH,
288286
CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR,
289287
CompileTimeErrorCode.RETURN_IN_GENERATOR,
288+
CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY,
290289
CompileTimeErrorCode.SHARED_DEFERRED_PREFIX,
290+
CompileTimeErrorCode.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
291291
CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT,
292292
CompileTimeErrorCode.SUPER_IN_EXTENSION,
293293
CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT,

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ class _ConstLiteralVerifier {
600600
return CompileTimeErrorCode
601601
.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY;
602602
} else if (forSet) {
603-
return CompileTimeErrorCode
604-
.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY;
603+
return CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY;
605604
}
606605

607606
return null;
@@ -640,10 +639,8 @@ class _ConstLiteralVerifier {
640639
// The errors have already been reported.
641640
if (conditionBool == null) return false;
642641

643-
verifier._reportErrorIfFromDeferredLibrary(
644-
element.condition,
645-
CompileTimeErrorCode
646-
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY);
642+
verifier._reportErrorIfFromDeferredLibrary(element.condition,
643+
CompileTimeErrorCode.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY);
647644

648645
var thenValid = true;
649646
var elseValid = true;
@@ -670,10 +667,8 @@ class _ConstLiteralVerifier {
670667
var value = verifier._validate(element.expression, errorCode);
671668
if (value == null) return false;
672669

673-
verifier._reportErrorIfFromDeferredLibrary(
674-
element.expression,
675-
CompileTimeErrorCode
676-
.NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY);
670+
verifier._reportErrorIfFromDeferredLibrary(element.expression,
671+
CompileTimeErrorCode.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY);
677672

678673
if (forList || forSet) {
679674
return _validateListOrSetSpread(element, value);
@@ -896,7 +891,7 @@ class _ConstLiteralVerifier {
896891

897892
verifier._reportErrorIfFromDeferredLibrary(
898893
expression,
899-
CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
894+
CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY,
900895
);
901896

902897
if (setUniqueValues.containsKey(value)) {

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,13 @@ class CompileTimeErrorCode extends ErrorCode {
14661466
"Try using an explicit typedef, or changing type parameters to "
14671467
"`dynamic`.");
14681468

1469+
static const CompileTimeErrorCode IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY =
1470+
const CompileTimeErrorCode(
1471+
'IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY',
1472+
"Constant values from a deferred library can't be used as values in "
1473+
"an if condition inside a const collection literal.",
1474+
correction: "Try making the deferred import non-deferred.");
1475+
14691476
/**
14701477
* 7.10 Superinterfaces: It is a compile-time error if the implements clause
14711478
* of a class <i>C</i> specifies a malformed type or deferred type as a
@@ -2625,30 +2632,6 @@ class CompileTimeErrorCode extends ErrorCode {
26252632
"The values in a const set literal must be constants.",
26262633
correction: "Try removing the keyword 'const' from the set literal.");
26272634

2628-
static const CompileTimeErrorCode
2629-
NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY =
2630-
const CompileTimeErrorCode(
2631-
'NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY',
2632-
"Constant values from a deferred library can't be spread into a "
2633-
"const literal.",
2634-
correction: "Try making the deferred import non-deferred.");
2635-
2636-
static const CompileTimeErrorCode
2637-
NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY =
2638-
const CompileTimeErrorCode(
2639-
'NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY',
2640-
"Constant values from a deferred library can't be used as values in "
2641-
"an if condition inside a const collection literal.",
2642-
correction: "Try making the deferred import non-deferred.");
2643-
2644-
static const CompileTimeErrorCode
2645-
NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY =
2646-
const CompileTimeErrorCode(
2647-
'NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY',
2648-
"Constant values from a deferred library can't be used as values in "
2649-
"a 'const' set.",
2650-
correction: "Try removing the keyword 'const' from the set literal.");
2651-
26522635
/**
26532636
* This error code is no longer being generated. It should be removed when the
26542637
* reference to it in the linter has been removed and rolled into the SDK.
@@ -3206,6 +3189,13 @@ class CompileTimeErrorCode extends ErrorCode {
32063189
"Try removing the value, replacing 'return' with 'yield' or "
32073190
"changing the method body modifier.");
32083191

3192+
static const CompileTimeErrorCode SET_ELEMENT_FROM_DEFERRED_LIBRARY =
3193+
const CompileTimeErrorCode(
3194+
'SET_ELEMENT_FROM_DEFERRED_LIBRARY',
3195+
"Constant values from a deferred library can't be used as values in "
3196+
"a const set.",
3197+
correction: "Try making the deferred import non-deferred.");
3198+
32093199
/**
32103200
* 14.1 Imports: It is a compile-time error if a prefix used in a deferred
32113201
* import is used in another import clause.
@@ -3217,6 +3207,13 @@ class CompileTimeErrorCode extends ErrorCode {
32173207
"directives.",
32183208
correction: "Try renaming one of the prefixes.");
32193209

3210+
static const CompileTimeErrorCode SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY =
3211+
const CompileTimeErrorCode(
3212+
'SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY',
3213+
"Constant values from a deferred library can't be spread into a "
3214+
"const literal.",
3215+
correction: "Try making the deferred import non-deferred.");
3216+
32203217
/**
32213218
* No parameters.
32223219
*/

pkg/analyzer/test/src/diagnostics/non_constant_if_element_condition_from_deferred_library_test.dart renamed to pkg/analyzer/test/src/diagnostics/if_element_condition_from_deferred_library_test.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import '../dart/resolution/driver_resolution.dart';
1111

1212
main() {
1313
defineReflectiveSuite(() {
14-
defineReflectiveTests(NonConstantIfElementConditionFromDeferredLibraryTest);
14+
defineReflectiveTests(IfElementConditionFromDeferredLibraryTest);
1515
defineReflectiveTests(
16-
NonConstantIfElementConditionFromDeferredLibraryWithConstantsTest);
16+
IfElementConditionFromDeferredLibraryWithConstantsTest);
1717
});
1818
}
1919

2020
@reflectiveTest
21-
class NonConstantIfElementConditionFromDeferredLibraryTest
22-
extends DriverResolutionTest {
21+
class IfElementConditionFromDeferredLibraryTest extends DriverResolutionTest {
2322
test_inList_deferred() async {
2423
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
2524
const bool c = true;''');
@@ -33,7 +32,7 @@ f() {
3332
? [
3433
error(
3534
CompileTimeErrorCode
36-
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
35+
.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
3736
59,
3837
3),
3938
]
@@ -81,7 +80,7 @@ f() {
8180
? [
8281
error(
8382
CompileTimeErrorCode
84-
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
83+
.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
8584
59,
8685
3),
8786
]
@@ -129,7 +128,7 @@ f() {
129128
? [
130129
error(
131130
CompileTimeErrorCode
132-
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
131+
.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
133132
59,
134133
3),
135134
]
@@ -166,8 +165,8 @@ f() {
166165
}
167166

168167
@reflectiveTest
169-
class NonConstantIfElementConditionFromDeferredLibraryWithConstantsTest
170-
extends NonConstantIfElementConditionFromDeferredLibraryTest {
168+
class IfElementConditionFromDeferredLibraryWithConstantsTest
169+
extends IfElementConditionFromDeferredLibraryTest {
171170
@override
172171
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
173172
..enabledExperiments = [EnableString.constant_update_2018];

pkg/analyzer/test/src/diagnostics/non_constant_set_element_from_deferred_library_test.dart renamed to pkg/analyzer/test/src/diagnostics/set_element_from_deferred_library_test.dart

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import '../dart/resolution/driver_resolution.dart';
1111

1212
main() {
1313
defineReflectiveSuite(() {
14-
defineReflectiveTests(NonConstantSetElementFromDeferredLibraryTest);
15-
defineReflectiveTests(
16-
NonConstantSetElementFromDeferredLibraryWithConstantsTest);
14+
defineReflectiveTests(SetElementFromDeferredLibraryTest);
15+
defineReflectiveTests(SetElementFromDeferredLibraryWithConstantsTest);
1716
});
1817
}
1918

2019
@reflectiveTest
21-
class NonConstantSetElementFromDeferredLibraryTest
22-
extends DriverResolutionTest {
20+
class SetElementFromDeferredLibraryTest extends DriverResolutionTest {
2321
@failingTest
2422
test_const_ifElement_thenTrue_elseDeferred() async {
2523
// reports wrong error code
@@ -30,8 +28,7 @@ import 'lib1.dart' deferred as a;
3028
const cond = true;
3129
var v = const {if (cond) null else a.c};
3230
''', [
33-
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
34-
88, 3),
31+
error(CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY, 88, 3),
3532
]);
3633
}
3734

@@ -46,11 +43,8 @@ var v = const {if (cond) a.c};
4643
''',
4744
analysisOptions.experimentStatus.constant_update_2018
4845
? [
49-
error(
50-
CompileTimeErrorCode
51-
.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
52-
78,
53-
3),
46+
error(CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY,
47+
78, 3),
5448
]
5549
: [
5650
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT, 68, 13),
@@ -64,8 +58,7 @@ const int c = 1;''');
6458
import 'lib1.dart' deferred as a;
6559
var v = const {a.c};
6660
''', [
67-
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
68-
49, 3),
61+
error(CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY, 49, 3),
6962
]);
7063
}
7164

@@ -76,15 +69,14 @@ const int c = 1;''');
7669
import 'lib1.dart' deferred as a;
7770
var v = const {a.c + 1};
7871
''', [
79-
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY,
80-
49, 7),
72+
error(CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY, 49, 7),
8173
]);
8274
}
8375
}
8476

8577
@reflectiveTest
86-
class NonConstantSetElementFromDeferredLibraryWithConstantsTest
87-
extends NonConstantSetElementFromDeferredLibraryTest {
78+
class SetElementFromDeferredLibraryWithConstantsTest
79+
extends SetElementFromDeferredLibraryTest {
8880
@override
8981
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
9082
..enabledExperiments = [EnableString.constant_update_2018];

pkg/analyzer/test/src/diagnostics/non_constant_spread_expression_from_deferred_library_test.dart renamed to pkg/analyzer/test/src/diagnostics/spread_expression_from_deferred_library_test.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import '../dart/resolution/driver_resolution.dart';
1111

1212
main() {
1313
defineReflectiveSuite(() {
14-
defineReflectiveTests(NonConstantSpreadExpressionFromDeferredLibraryTest);
15-
defineReflectiveTests(
16-
NonConstantSpreadExpressionFromDeferredLibraryWithConstantsTest);
14+
defineReflectiveTests(SpreadExpressionFromDeferredLibraryTest);
15+
defineReflectiveTests(SpreadExpressionFromDeferredLibraryWithConstantsTest);
1716
});
1817
}
1918

2019
@reflectiveTest
21-
class NonConstantSpreadExpressionFromDeferredLibraryTest
22-
extends DriverResolutionTest {
20+
class SpreadExpressionFromDeferredLibraryTest extends DriverResolutionTest {
2321
test_inList_deferred() async {
2422
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
2523
const List c = [];''');
@@ -33,7 +31,7 @@ f() {
3331
? [
3432
error(
3533
CompileTimeErrorCode
36-
.NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
34+
.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
3735
59,
3836
3),
3937
]
@@ -81,7 +79,7 @@ f() {
8179
? [
8280
error(
8381
CompileTimeErrorCode
84-
.NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
82+
.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
8583
59,
8684
3),
8785
]
@@ -129,7 +127,7 @@ f() {
129127
? [
130128
error(
131129
CompileTimeErrorCode
132-
.NON_CONSTANT_SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
130+
.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
133131
59,
134132
3),
135133
]
@@ -166,8 +164,8 @@ f() {
166164
}
167165

168166
@reflectiveTest
169-
class NonConstantSpreadExpressionFromDeferredLibraryWithConstantsTest
170-
extends NonConstantSpreadExpressionFromDeferredLibraryTest {
167+
class SpreadExpressionFromDeferredLibraryWithConstantsTest
168+
extends SpreadExpressionFromDeferredLibraryTest {
171169
@override
172170
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
173171
..enabledExperiments = [EnableString.constant_update_2018];

0 commit comments

Comments
 (0)