Skip to content

Commit 588ab11

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Unify two error codes that are essentially identical
The original reason for the difference is that one was used for run-time exceptions that become static errors in constant evaluation, but that distinction does not seem to be necessary any more. Change-Id: Ie16ad623e292f9755cbe316755210097870a1515 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108301 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fcc72ad commit 588ab11

File tree

6 files changed

+31
-79
lines changed

6 files changed

+31
-79
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ const List<ErrorCode> errorCodeValues = const [
606606
StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
607607
StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
608608
StaticTypeWarningCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE,
609-
StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
610609
StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
611610
StaticTypeWarningCode.UNDEFINED_ENUM_CONSTANT,
612611
StaticTypeWarningCode.UNDEFINED_FUNCTION,

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,8 +2973,6 @@ class CompileTimeErrorCode extends ErrorCode {
29732973
* 0: the name of the type used in the instance creation that should be
29742974
* limited by the bound as specified in the class declaration
29752975
* 1: the name of the bounding type
2976-
*
2977-
* See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
29782976
*/
29792977
static const CompileTimeErrorCode TYPE_ARGUMENT_NOT_MATCHING_BOUNDS =
29802978
const CompileTimeErrorCode(
@@ -3503,39 +3501,6 @@ class StaticTypeWarningCode extends ErrorCode {
35033501
const StaticTypeWarningCode('RETURN_OF_INVALID_TYPE_FROM_CLOSURE',
35043502
"The return type '{0}' isn't a '{1}', as defined by anonymous closure.");
35053503

3506-
/**
3507-
* 12.11 Instance Creation: It is a static type warning if any of the type
3508-
* arguments to a constructor of a generic type <i>G</i> invoked by a new
3509-
* expression or a constant object expression are not subtypes of the bounds
3510-
* of the corresponding formal type parameters of <i>G</i>.
3511-
*
3512-
* 15.8 Parameterized Types: If <i>S</i> is the static type of a member
3513-
* <i>m</i> of <i>G</i>, then the static type of the member <i>m</i> of
3514-
* <i>G&lt;A<sub>1</sub>, &hellip;, A<sub>n</sub>&gt;</i> is <i>[A<sub>1</sub>,
3515-
* &hellip;, A<sub>n</sub>/T<sub>1</sub>, &hellip;, T<sub>n</sub>]S</i> where
3516-
* <i>T<sub>1</sub>, &hellip;, T<sub>n</sub></i> are the formal type
3517-
* parameters of <i>G</i>. Let <i>B<sub>i</sub></i> be the bounds of
3518-
* <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>. It is a static type warning if
3519-
* <i>A<sub>i</sub></i> is not a subtype of <i>[A<sub>1</sub>, &hellip;,
3520-
* A<sub>n</sub>/T<sub>1</sub>, &hellip;, T<sub>n</sub>]B<sub>i</sub>, 1 &lt;=
3521-
* i &lt;= n</i>.
3522-
*
3523-
* 7.6.2 Factories: It is a static type warning if any of the type arguments
3524-
* to <i>k'</i> are not subtypes of the bounds of the corresponding formal
3525-
* type parameters of type.
3526-
*
3527-
* Parameters:
3528-
* 0: the name of the type used in the instance creation that should be
3529-
* limited by the bound as specified in the class declaration
3530-
* 1: the name of the bounding type
3531-
*
3532-
* See [TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND].
3533-
*/
3534-
static const StaticTypeWarningCode TYPE_ARGUMENT_NOT_MATCHING_BOUNDS =
3535-
const StaticTypeWarningCode(
3536-
'TYPE_ARGUMENT_NOT_MATCHING_BOUNDS', "'{0}' doesn't extend '{1}'.",
3537-
correction: "Try using a type that is or is a subclass of '{1}'.");
3538-
35393504
/**
35403505
* 10 Generics: It is a static type warning if a type parameter is a supertype
35413506
* of its upper bound.
@@ -3544,7 +3509,7 @@ class StaticTypeWarningCode extends ErrorCode {
35443509
* 0: the name of the type parameter
35453510
* 1: the name of the bounding type
35463511
*
3547-
* See [TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
3512+
* See [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
35483513
*/
35493514
static const StaticTypeWarningCode TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND =
35503515
const StaticTypeWarningCode('TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND',

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5390,10 +5390,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
53905390
/**
53915391
* Verify that the type arguments in the given [typeName] are all within
53925392
* their bounds.
5393-
*
5394-
* See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS],
5395-
* [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS],
5396-
* [CompileTimeErrorCode.GENERIC_FUNCTION_CANNOT_BE_BOUND].
53975393
*/
53985394
void _checkForTypeArgumentNotMatchingBounds(TypeName typeName) {
53995395
// prepare Type
@@ -5453,14 +5449,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
54535449
}
54545450

54555451
if (!_typeSystem.isSubtypeOf(argType, boundType)) {
5456-
ErrorCode errorCode;
5457-
if (_isInConstInstanceCreation) {
5458-
errorCode =
5459-
CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5460-
} else {
5461-
errorCode =
5462-
StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5463-
}
54645452
if (_shouldAllowSuperBoundedTypes(typeName)) {
54655453
var replacedType =
54665454
(argType as TypeImpl).replaceTopAndBottom(_typeProvider);
@@ -5471,7 +5459,9 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
54715459
}
54725460
}
54735461
_errorReporter.reportTypeErrorForNode(
5474-
errorCode, argumentNode, [argType, boundType]);
5462+
CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
5463+
argumentNode,
5464+
[argType, boundType]);
54755465
}
54765466
}
54775467
}
@@ -5981,8 +5971,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
59815971
/**
59825972
* Verify that the given [typeArguments] are all within their bounds, as
59835973
* defined by the given [element].
5984-
*
5985-
* See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
59865974
*/
59875975
void _checkTypeArguments(InvocationExpression node) {
59885976
NodeList<TypeAnnotation> typeArgumentList = node.typeArguments?.arguments;
@@ -6027,7 +6015,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
60276015
fnTypeParams[i].bound.substitute2(typeArgs, fnTypeParams);
60286016
if (!_typeSystem.isSubtypeOf(argType, bound)) {
60296017
_errorReporter.reportTypeErrorForNode(
6030-
StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
6018+
CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
60316019
typeArgumentList[i],
60326020
[argType, bound]);
60336021
}

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ class Bar<T extends Foo<T>> {}
24592459
class Baz extends Bar {}
24602460
void main() {}
24612461
''', [
2462-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 65, 3),
2462+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 65, 3),
24632463
]);
24642464
// Instantiate-to-bounds should have instantiated "Bar" to "Bar<Foo>".
24652465
expect(result.unit.declaredElement.getType('Baz').supertype.toString(),
@@ -5148,7 +5148,7 @@ typedef A B();
51485148
];
51495149
if (!AnalysisDriver.useSummary2) {
51505150
errors.add(
5151-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 22, 3),
5151+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 22, 3),
51525152
);
51535153
}
51545154
await assertErrorsInCode('''

pkg/analyzer/test/generated/static_type_warning_code_test.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ class C {}
10711071
class G<E extends A> {}
10721072
class D = G<B> with C;
10731073
''', [
1074-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 69, 1),
1074+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 69, 1),
10751075
]);
10761076
}
10771077

@@ -1082,7 +1082,7 @@ class B {}
10821082
class G<E extends A> {}
10831083
class C extends G<B>{}
10841084
''', [
1085-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 64, 1),
1085+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 64, 1),
10861086
]);
10871087
}
10881088

@@ -1092,7 +1092,7 @@ class C extends G<B>{}
10921092
class X<T extends Type> {}
10931093
class Y<U> extends X<U> {}
10941094
''', [
1095-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
1095+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
10961096
]);
10971097
}
10981098

@@ -1106,7 +1106,7 @@ class C {
11061106
C(G<B> this.f) {}
11071107
}
11081108
''', [
1109-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 71, 1),
1109+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 71, 1),
11101110
]);
11111111
}
11121112

@@ -1117,7 +1117,7 @@ class B {}
11171117
class G<E extends A> {}
11181118
G<B> f() { return null; }
11191119
''', [
1120-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
1120+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
11211121
]);
11221122
}
11231123

@@ -1128,7 +1128,7 @@ class B {}
11281128
class G<E extends A> {}
11291129
typedef G<B> f();
11301130
''', [
1131-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 1),
1131+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 1),
11321132
]);
11331133
}
11341134

@@ -1139,7 +1139,7 @@ class B {}
11391139
class G<E extends A> {}
11401140
f(G<B> h()) {}
11411141
''', [
1142-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
1142+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
11431143
]);
11441144
}
11451145

@@ -1150,7 +1150,7 @@ class B {}
11501150
class G<E extends A> {}
11511151
class C implements G<B>{}
11521152
''', [
1153-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 67, 1),
1153+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 67, 1),
11541154
]);
11551155
}
11561156

@@ -1161,7 +1161,7 @@ class B {}
11611161
class G<E extends A> {}
11621162
var b = 1 is G<B>;
11631163
''', [
1164-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 61, 1),
1164+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 61, 1),
11651165
]);
11661166
}
11671167

@@ -1178,7 +1178,7 @@ main() {
11781178
print(f<String>('hello', 'world'));
11791179
}
11801180
''', [
1181-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 145, 6),
1181+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 145, 6),
11821182
]);
11831183
}
11841184

@@ -1198,7 +1198,7 @@ f(PointFactory factory) {
11981198
print(factory.point<String>('hello', 'world'));
11991199
}
12001200
''', [
1201-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 202, 6),
1201+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 202, 6),
12021202
]);
12031203
}
12041204

@@ -1216,7 +1216,7 @@ main() {
12161216
print(f<String>('hello', 'world'));
12171217
}
12181218
''', [
1219-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 140, 6),
1219+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 140, 6),
12201220
]);
12211221
}
12221222

@@ -1229,7 +1229,7 @@ class C {
12291229
G<B> m() { return null; }
12301230
}
12311231
''', [
1232-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
1232+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
12331233
]);
12341234
}
12351235

@@ -1240,7 +1240,7 @@ class B {}
12401240
class G<E extends A> {}
12411241
f() { return new G<B>(); }
12421242
''', [
1243-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 65, 1),
1243+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 65, 1),
12441244
]);
12451245
}
12461246

@@ -1252,7 +1252,7 @@ class C extends B {}
12521252
class G<E extends B> {}
12531253
f() { return new G<A>(); }
12541254
''', [
1255-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 96, 1),
1255+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 96, 1),
12561256
]);
12571257
}
12581258

@@ -1263,7 +1263,7 @@ class B {}
12631263
typedef F<T extends A>();
12641264
F<B> fff;
12651265
''', [
1266-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
1266+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
12671267
]);
12681268
}
12691269

@@ -1274,7 +1274,7 @@ class B {}
12741274
class G<E extends A> {}
12751275
f(G<B> g) {}
12761276
''', [
1277-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
1277+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 50, 1),
12781278
]);
12791279
}
12801280

@@ -1288,7 +1288,7 @@ class X<T extends A> {
12881288
}
12891289
''', [
12901290
error(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, 99, 4),
1291-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 101, 1),
1291+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 101, 1),
12921292
]);
12931293
}
12941294

@@ -1300,7 +1300,7 @@ class C<E> {}
13001300
class D<E extends A> {}
13011301
C<D<B>> Var;
13021302
''', [
1303-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 64, 1),
1303+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 64, 1),
13041304
]);
13051305
}
13061306

@@ -1312,7 +1312,7 @@ class C {}
13121312
class G<E extends A> {}
13131313
class D<F extends G<B>> {}
13141314
''', [
1315-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 77, 1),
1315+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 77, 1),
13161316
]);
13171317
}
13181318

@@ -1323,7 +1323,7 @@ class B {}
13231323
class G<E extends A> {}
13241324
G<B> g;
13251325
''', [
1326-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
1326+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 48, 1),
13271327
]);
13281328
}
13291329

@@ -1334,7 +1334,7 @@ class B {}
13341334
class G<E extends A> {}
13351335
class C extends Object with G<B>{}
13361336
''', [
1337-
error(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 76, 1),
1337+
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 76, 1),
13381338
]);
13391339
}
13401340

pkg/analyzer/test/generated/strong_mode_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,7 @@ class D extends C {}
50515051
''';
50525052
await resolveTestUnit(code, noErrors: false);
50535053
assertErrors(
5054-
testSource, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
5054+
testSource, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
50555055
}
50565056

50575057
test_instantiateToBounds_class_error_instantiation_malbounded() async {
@@ -5066,7 +5066,7 @@ void test() {
50665066
await resolveTestUnit(code, noErrors: false);
50675067
assertErrors(testSource, [
50685068
StrongModeCode.COULD_NOT_INFER,
5069-
StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
5069+
CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
50705070
]);
50715071
expectIdentifierType('c =', 'C<List<dynamic>, List<List<dynamic>>>');
50725072
}

0 commit comments

Comments
 (0)