analyzer: Combine non-function-typedef test classes with null-safety test classes
In each file, test cases were simply moved, and not changed at all. No test
cases are removed. None are added.
Bug: https://github.com/dart-lang/sdk/issues/44666
Change-Id: I7566602f53a234b34e3dc54176ac9b80139f444b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186761
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
index e9319da..60d4e16 100644
--- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
@@ -15,9 +15,6 @@
defineReflectiveSuite(() {
defineReflectiveTests(MethodInvocationResolutionTest);
defineReflectiveTests(MethodInvocationResolutionWithNullSafetyTest);
- defineReflectiveTests(
- MethodInvocationResolutionWithNonFunctionTypeAliasesTest,
- );
});
}
@@ -2447,66 +2444,9 @@
}
}
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one it extends.
-@reflectiveTest
-class MethodInvocationResolutionWithNonFunctionTypeAliasesTest
- extends PubPackageResolutionTest {
- test_hasReceiver_typeAlias_staticMethod() async {
- await assertNoErrorsInCode(r'''
-class A {
- static void foo(int _) {}
-}
-
-typedef B = A;
-
-void f() {
- B.foo(0);
-}
-''');
-
- assertMethodInvocation(
- findNode.methodInvocation('foo(0)'),
- findElement.method('foo'),
- 'void Function(int)',
- );
-
- assertTypeAliasRef(
- findNode.simple('B.foo'),
- findElement.typeAlias('B'),
- );
- }
-
- test_hasReceiver_typeAlias_staticMethod_generic() async {
- await assertNoErrorsInCode(r'''
-class A<T> {
- static void foo(int _) {}
-}
-
-typedef B<T> = A<T>;
-
-void f() {
- B.foo(0);
-}
-''');
-
- assertMethodInvocation(
- findNode.methodInvocation('foo(0)'),
- findElement.method('foo'),
- 'void Function(int)',
- );
-
- assertTypeAliasRef(
- findNode.simple('B.foo'),
- findElement.typeAlias('B'),
- );
- }
-}
-
@reflectiveTest
class MethodInvocationResolutionWithNullSafetyTest
- extends PubPackageResolutionTest
- with WithNullSafetyMixin, MethodInvocationResolutionTestCases {
+ extends PubPackageResolutionTest with MethodInvocationResolutionTestCases {
test_hasReceiver_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
newFile('$testPackageLibPath/a.dart', content: r'''
class A {}
@@ -2764,6 +2704,56 @@
);
}
+ test_hasReceiver_typeAlias_staticMethod() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ static void foo(int _) {}
+}
+
+typedef B = A;
+
+void f() {
+ B.foo(0);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('foo(0)'),
+ findElement.method('foo'),
+ 'void Function(int)',
+ );
+
+ assertTypeAliasRef(
+ findNode.simple('B.foo'),
+ findElement.typeAlias('B'),
+ );
+ }
+
+ test_hasReceiver_typeAlias_staticMethod_generic() async {
+ await assertNoErrorsInCode(r'''
+class A<T> {
+ static void foo(int _) {}
+}
+
+typedef B<T> = A<T>;
+
+void f() {
+ B.foo(0);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('foo(0)'),
+ findElement.method('foo'),
+ 'void Function(int)',
+ );
+
+ assertTypeAliasRef(
+ findNode.simple('B.foo'),
+ findElement.typeAlias('B'),
+ );
+ }
+
test_hasReceiver_typeParameter_promotedToNonNullable() async {
await assertNoErrorsInCode('''
void f<T>(T? t) {
diff --git a/pkg/analyzer/test/src/diagnostics/const_initialized_with_non_constant_value_test.dart b/pkg/analyzer/test/src/diagnostics/const_initialized_with_non_constant_value_test.dart
index 4776e89..17d8a68 100644
--- a/pkg/analyzer/test/src/diagnostics/const_initialized_with_non_constant_value_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/const_initialized_with_non_constant_value_test.dart
@@ -10,9 +10,6 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConstInitializedWithNonConstantValueTest);
- defineReflectiveTests(
- ConstInitializedWithNonConstantValueWithNonFunctionTypeAliasesTest,
- );
});
}
@@ -105,13 +102,7 @@
1),
]);
}
-}
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one above it.
-@reflectiveTest
-class ConstInitializedWithNonConstantValueWithNonFunctionTypeAliasesTest
- extends PubPackageResolutionTest {
test_typeLiteral_interfaceType() async {
await assertNoErrorsInCode(r'''
const a = int;
diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart
index da6d102..af8e6e3 100644
--- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart
@@ -13,8 +13,6 @@
});
}
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one above it.
@reflectiveTest
class NullableTypeInOnClauseTest extends PubPackageResolutionTest {
test_nonNullable() async {
diff --git a/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart b/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart
index 831cfaa..68ba41b 100644
--- a/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart
@@ -10,9 +10,6 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(TypeAliasCannotReferenceItselfTest);
- defineReflectiveTests(
- TypeAliasCannotReferenceItselfWithNonFunctionTypeAliasesTest,
- );
});
}
@@ -91,6 +88,56 @@
''');
}
+ test_nonFunction_aliasedType_cycleOf2() async {
+ await assertErrorsInCode('''
+typedef T1 = T2;
+typedef T2 = T1;
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 16),
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 17, 16),
+ ]);
+ }
+
+ test_nonFunction_aliasedType_directly_functionWithIt() async {
+ await assertErrorsInCode('''
+typedef T = void Function(T);
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 29),
+ ]);
+ }
+
+ test_nonFunction_aliasedType_directly_it_none() async {
+ await assertErrorsInCode('''
+typedef T = T;
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 14),
+ ]);
+ }
+
+ test_nonFunction_aliasedType_directly_it_question() async {
+ await assertErrorsInCode('''
+typedef T = T?;
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 15),
+ ]);
+ }
+
+ test_nonFunction_aliasedType_directly_ListOfIt() async {
+ await assertErrorsInCode('''
+typedef T = List<T>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 20),
+ ]);
+ }
+
+ test_nonFunction_typeParameterBounds() async {
+ await assertErrorsInCode('''
+typedef T<X extends T<Never>> = List<X>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 40),
+ ]);
+ }
+
test_parameterType_named() async {
await assertErrorsInCode('''
typedef A({A a});
@@ -161,59 +208,3 @@
]);
}
}
-
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one it extends.
-@reflectiveTest
-class TypeAliasCannotReferenceItselfWithNonFunctionTypeAliasesTest
- extends PubPackageResolutionTest {
- test_nonFunction_aliasedType_cycleOf2() async {
- await assertErrorsInCode('''
-typedef T1 = T2;
-typedef T2 = T1;
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 16),
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 17, 16),
- ]);
- }
-
- test_nonFunction_aliasedType_directly_functionWithIt() async {
- await assertErrorsInCode('''
-typedef T = void Function(T);
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 29),
- ]);
- }
-
- test_nonFunction_aliasedType_directly_it_none() async {
- await assertErrorsInCode('''
-typedef T = T;
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 14),
- ]);
- }
-
- test_nonFunction_aliasedType_directly_it_question() async {
- await assertErrorsInCode('''
-typedef T = T?;
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 15),
- ]);
- }
-
- test_nonFunction_aliasedType_directly_ListOfIt() async {
- await assertErrorsInCode('''
-typedef T = List<T>;
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 20),
- ]);
- }
-
- test_nonFunction_typeParameterBounds() async {
- await assertErrorsInCode('''
-typedef T<X extends T<Never>> = List<X>;
-''', [
- error(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 0, 40),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
index b33e321..b9850fb 100644
--- a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
@@ -13,9 +13,6 @@
defineReflectiveTests(
TypeArgumentNotMatchingBoundsWithNullSafetyTest,
);
- defineReflectiveTests(
- TypeArgumentNotMatchingBoundsWithNonFunctionTypeAliasesTest,
- );
});
}
@@ -418,44 +415,10 @@
}
}
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one it extends.
-@reflectiveTest
-class TypeArgumentNotMatchingBoundsWithNonFunctionTypeAliasesTest
- extends PubPackageResolutionTest
- with TypeArgumentNotMatchingBoundsTestCases {
- test_nonFunctionTypeAlias_interfaceType_parameter() async {
- await assertErrorsInCode(r'''
-class A {}
-typedef X<T extends A> = Map<int, T>;
-void f(X<String> a) {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 58, 6),
- ]);
- }
-
- test_nonFunctionTypeAlias_interfaceType_parameter_regularBounded() async {
- await assertNoErrorsInCode(r'''
-class A {}
-class B extends A {}
-typedef X<T extends A> = Map<int, T>;
-void f(X<B> a) {}
-''');
- }
-
- test_nonFunctionTypeAlias_interfaceType_parameter_superBounded() async {
- await assertNoErrorsInCode(r'''
-class A {}
-typedef X<T extends A> = Map<int, T>;
-void f(X<Never> a) {}
-''');
- }
-}
-
@reflectiveTest
class TypeArgumentNotMatchingBoundsWithNullSafetyTest
extends PubPackageResolutionTest
- with TypeArgumentNotMatchingBoundsTestCases, WithNullSafetyMixin {
+ with TypeArgumentNotMatchingBoundsTestCases {
test_extends_optIn_fromOptOut_Null() async {
newFile('$testPackageLibPath/a.dart', content: r'''
class A<X extends int> {}
@@ -488,6 +451,33 @@
''');
}
+ test_nonFunctionTypeAlias_interfaceType_parameter() async {
+ await assertErrorsInCode(r'''
+class A {}
+typedef X<T extends A> = Map<int, T>;
+void f(X<String> a) {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 58, 6),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_parameter_regularBounded() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+class B extends A {}
+typedef X<T extends A> = Map<int, T>;
+void f(X<B> a) {}
+''');
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_parameter_superBounded() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+typedef X<T extends A> = Map<int, T>;
+void f(X<Never> a) {}
+''');
+ }
+
test_notRegularBounded_notSuperBounded_invariant() async {
await assertErrorsInCode(r'''
typedef A<X> = X Function(X);
diff --git a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
index de7dc23..c3ca7ec 100644
--- a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
@@ -11,7 +11,6 @@
defineReflectiveSuite(() {
defineReflectiveTests(UnusedElementTest);
defineReflectiveTests(UnusedElementWithNullSafetyTest);
- defineReflectiveTests(UnusedElementWithNonFunctionTypeAliasesTest);
});
}
@@ -1578,11 +1577,20 @@
}
}
-/// TODO(https://github.com/dart-lang/sdk/issues/44666): Combine this class
-/// with the one it extends.
@reflectiveTest
-class UnusedElementWithNonFunctionTypeAliasesTest
- extends PubPackageResolutionTest {
+class UnusedElementWithNullSafetyTest extends PubPackageResolutionTest {
+ test_optionalParameter_isUsed_overrideRequiredNamed() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ void _m({required int a}) {}
+}
+class B implements A {
+ void _m({int a = 0}) {}
+}
+f() => A()._m(a: 0);
+''');
+ }
+
test_typeAlias_interfaceType_isUsed_typeName_isExpression() async {
await assertNoErrorsInCode(r'''
typedef _A = List<int>;
@@ -1619,19 +1627,3 @@
]);
}
}
-
-@reflectiveTest
-class UnusedElementWithNullSafetyTest extends PubPackageResolutionTest
- with WithNullSafetyMixin {
- test_optionalParameter_isUsed_overrideRequiredNamed() async {
- await assertNoErrorsInCode(r'''
-class A {
- void _m({required int a}) {}
-}
-class B implements A {
- void _m({int a = 0}) {}
-}
-f() => A()._m(a: 0);
-''');
- }
-}