Skip to content

Commit 907da64

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Analyzer: Redefine NOT_INSTANTIATED_BOUND to be an error.
All StrongModeCodes are being redefined. #33545 Change-Id: I247c6584eba386edfd7babecb08adf5ccc9344ed Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154748 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 9dca49e commit 907da64

File tree

7 files changed

+196
-174
lines changed

7 files changed

+196
-174
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ const List<ErrorCode> errorCodeValues = [
272272
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD,
273273
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD_CONSTRUCTOR,
274274
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE,
275+
CompileTimeErrorCode.NOT_INSTANTIATED_BOUND,
275276
CompileTimeErrorCode.NOT_ITERABLE_SPREAD,
276277
CompileTimeErrorCode.NOT_MAP_SPREAD,
277278
CompileTimeErrorCode.NOT_NULL_AWARE_NULL_SPREAD,
@@ -837,7 +838,6 @@ const List<ErrorCode> errorCodeValues = [
837838
StrongModeCode.INVALID_CAST_NEW_EXPR,
838839
StrongModeCode.INVALID_PARAMETER_DECLARATION,
839840
StrongModeCode.INVALID_SUPER_INVOCATION,
840-
StrongModeCode.NOT_INSTANTIATED_BOUND,
841841
StrongModeCode.TOP_LEVEL_CYCLE,
842842
StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_BLOCK,
843843
StrongModeCode.TOP_LEVEL_IDENTIFIER_NO_TYPE,

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5194,6 +5194,14 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
51945194
correction: "Try adding an initializer expression.",
51955195
hasPublishedDocs: true);
51965196

5197+
/**
5198+
* No parameters.
5199+
*/
5200+
static const CompileTimeErrorCode NOT_INSTANTIATED_BOUND =
5201+
CompileTimeErrorCode('NOT_INSTANTIATED_BOUND',
5202+
'Type parameter bound types must be instantiated.',
5203+
correction: 'Try adding type arguments to the type parameter bound.');
5204+
51975205
/**
51985206
* No parameters.
51995207
*/
@@ -10809,12 +10817,6 @@ class StrongModeCode extends ErrorCode {
1080910817
"Missing type arguments for calling generic function type '{0}'.",
1081010818
correction: _implicitDynamicCorrection);
1081110819

10812-
static const StrongModeCode NOT_INSTANTIATED_BOUND = StrongModeCode(
10813-
ErrorType.COMPILE_TIME_ERROR,
10814-
'NOT_INSTANTIATED_BOUND',
10815-
"Type parameter bound types must be instantiated.",
10816-
correction: "Try adding type arguments.");
10817-
1081810820
/*
1081910821
* TODO(brianwilkerson) Make the TOP_LEVEL_ error codes be errors rather than
1082010822
* hints and then clean up the function _errorSeverity in

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5281,8 +5281,10 @@ class _UninstantiatedBoundChecker extends RecursiveAstVisitor<void> {
52815281

52825282
var element = node.name.staticElement;
52835283
if (element is TypeParameterizedElement && !element.isSimplyBounded) {
5284-
_errorReporter
5285-
.reportErrorForNode(StrongModeCode.NOT_INSTANTIATED_BOUND, node, []);
5284+
// TODO(srawlins): Don't report this if TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
5285+
// has been reported.
5286+
_errorReporter.reportErrorForNode(
5287+
CompileTimeErrorCode.NOT_INSTANTIATED_BOUND, node, []);
52865288
}
52875289
}
52885290
}

pkg/analyzer/test/generated/strong_mode_test.dart

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,168 +3526,6 @@ class C<E> {
35263526
''');
35273527
}
35283528

3529-
test_notInstantiatedBound_class_error_recursion() async {
3530-
await assertErrorsInCode(r'''
3531-
class A<T extends B> {} // points to a
3532-
class B<T extends A> {} // points to b
3533-
class C<T extends A> {} // points to a cyclical type
3534-
''', [
3535-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 18, 1),
3536-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 57, 1),
3537-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 96, 1),
3538-
]);
3539-
}
3540-
3541-
test_notInstantiatedBound_class_error_recursion_less_direct() async {
3542-
await assertErrorsInCode(r'''
3543-
class A<T extends B<A>> {}
3544-
class B<T extends A<B>> {}
3545-
''', [
3546-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 20, 1),
3547-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 47, 1),
3548-
]);
3549-
}
3550-
3551-
test_notInstantiatedBound_class_error_recursion_typedef() async {
3552-
await assertErrorsInCode(r'''
3553-
typedef F(C value);
3554-
class C<T extends F> {}
3555-
class D<T extends C> {}
3556-
''', [
3557-
error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 19),
3558-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 38, 1),
3559-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 62, 1),
3560-
]);
3561-
}
3562-
3563-
test_notInstantiatedBound_error_class_argument() async {
3564-
await assertErrorsInCode(r'''
3565-
class A<K, V extends List<K>> {}
3566-
class C<T extends A> {}
3567-
''', [
3568-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 51, 1),
3569-
]);
3570-
}
3571-
3572-
test_notInstantiatedBound_error_class_argument2() async {
3573-
await assertErrorsInCode(r'''
3574-
class A<K, V extends List<List<K>>> {}
3575-
class C<T extends A> {}
3576-
''', [
3577-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 57, 1),
3578-
]);
3579-
}
3580-
3581-
test_notInstantiatedBound_error_class_direct() async {
3582-
await assertErrorsInCode(r'''
3583-
class A<K, V extends K> {}
3584-
class C<T extends A> {}
3585-
''', [
3586-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 45, 1),
3587-
]);
3588-
}
3589-
3590-
test_notInstantiatedBound_error_class_indirect() async {
3591-
await assertErrorsInCode(r'''
3592-
class A<K, V extends K> {}
3593-
class C<T extends List<A>> {}
3594-
''', [
3595-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 50, 1),
3596-
]);
3597-
}
3598-
3599-
test_notInstantiatedBound_error_functionType() async {
3600-
await assertErrorsInCode(r'''
3601-
class A<T extends Function(T)> {}
3602-
class B<T extends T Function()> {}
3603-
class C<T extends A> {}
3604-
class D<T extends B> {}
3605-
''', [
3606-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 87, 1),
3607-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 111, 1),
3608-
]);
3609-
}
3610-
3611-
test_notInstantiatedBound_error_typedef_argument() async {
3612-
await assertErrorsInCode(r'''
3613-
class A<K, V extends List<K>> {}
3614-
typedef void F<T extends A>();
3615-
''', [
3616-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 58, 1),
3617-
]);
3618-
}
3619-
3620-
test_notInstantiatedBound_error_typedef_argument2() async {
3621-
await assertErrorsInCode(r'''
3622-
class A<K, V extends List<List<K>>> {}
3623-
typedef void F<T extends A>();
3624-
''', [
3625-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 64, 1),
3626-
]);
3627-
}
3628-
3629-
test_notInstantiatedBound_error_typedef_direct() async {
3630-
await assertErrorsInCode(r'''
3631-
class A<K, V extends K> {}
3632-
typedef void F<T extends A>();
3633-
''', [
3634-
error(StrongModeCode.NOT_INSTANTIATED_BOUND, 52, 1),
3635-
]);
3636-
}
3637-
3638-
test_notInstantiatedBound_ok_class() async {
3639-
await assertNoErrorsInCode(r'''
3640-
class A<T extends int> {}
3641-
class C1<T extends A> {}
3642-
class C2<T extends List<A>> {}
3643-
''');
3644-
}
3645-
3646-
test_notInstantiatedBound_ok_class_class2() async {
3647-
await assertNoErrorsInCode(r'''
3648-
class A<T> {}
3649-
class C<T extends A<int>> {}
3650-
class D<T extends C> {}
3651-
''');
3652-
}
3653-
3654-
test_notInstantiatedBound_ok_class_class3() async {
3655-
await assertNoErrorsInCode(r'''
3656-
class A<T> {}
3657-
class B<T extends int> {}
3658-
class C<T extends A<B>> {}
3659-
''');
3660-
}
3661-
3662-
test_notInstantiatedBound_ok_class_class4() async {
3663-
await assertNoErrorsInCode(r'''
3664-
class A<K, V> {}
3665-
class B<T extends int> {}
3666-
class C<T extends A<B, B>> {}
3667-
''');
3668-
}
3669-
3670-
test_notInstantiatedBound_ok_class_function() async {
3671-
await assertNoErrorsInCode(r'''
3672-
class A<T extends void Function()> {}
3673-
class B<T extends A> {}
3674-
''');
3675-
}
3676-
3677-
test_notInstantiatedBound_ok_class_typedef() async {
3678-
await assertNoErrorsInCode(r'''
3679-
typedef void F<T extends int>();
3680-
class C<T extends F> {}
3681-
''');
3682-
}
3683-
3684-
test_notInstantiatedBound_ok_typedef_class() async {
3685-
await assertNoErrorsInCode(r'''
3686-
class C<T extends int> {}
3687-
typedef void F<T extends C>();
3688-
''');
3689-
}
3690-
36913529
test_objectMethodOnFunctions_Anonymous() async {
36923530
await _objectMethodOnFunctions_helper2(r'''
36933531
void main() {

0 commit comments

Comments
 (0)