diff --git a/pkg/analyzer/test/src/diagnostics/wrong_number_of_type_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/wrong_number_of_type_arguments_test.dart index eb1a01277a8..48a7c291d7a 100644 --- a/pkg/analyzer/test/src/diagnostics/wrong_number_of_type_arguments_test.dart +++ b/pkg/analyzer/test/src/diagnostics/wrong_number_of_type_arguments_test.dart @@ -199,6 +199,405 @@ f(void Function() foo, void Function() bar) { ); } + test_messageText_annotation() async { + await assertErrorsInCode( + r''' +class A { + const A(); +} + +@A() +void f() {} +''', + [ + error( + diag.wrongNumberOfTypeArguments, + 28, + 5, + messageContains: [ + // TODO(paulberry): This message text could be better. See + // https://github.com/dart-lang/sdk/issues/62398. + "The type 'A Function()'", + '0 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_constructorInvocationWithExplicitNew_noTypeParameters() async { + await assertErrorsInCode( + r''' +class Foo { + Foo.bar(); +} + +main() { + new Foo.bar(); +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsConstructor, + 53, + 5, + messageContains: [ + "The constructor 'Foo.bar'", + "doesn't have type parameters", + ], + ), + ], + ); + } + + test_messageText_constructorInvocationWithImplicitNew_noTypeParameters() async { + await assertErrorsInCode( + r''' +class Foo { + Foo.bar(); +} + +main() { + Foo.bar(); +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsConstructor, + 49, + 5, + messageContains: [ + "The constructor 'Foo.bar'", + "doesn't have type parameters", + ], + ), + ], + ); + } + + test_messageText_constructorTearoff_noTypeParametersExpected() async { + await assertErrorsInCode( + ''' +class A { + A.foo() {} +} + +var x = A.foo; +''', + [ + error( + diag.wrongNumberOfTypeArgumentsConstructor, + 42, + 5, + messageContains: [ + "The constructor 'A.foo'", + "doesn't have type parameters", + ], + ), + ], + ); + } + + test_messageText_dotShorthand() async { + await assertErrorsInCode( + r''' +abstract class Foo { + const factory Foo.a() = _Foo; + + const Foo(); +} + +class _Foo extends Foo { + const _Foo(); +} + +Foo bar() => const .a(); +''', + [ + error( + diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, + 154, + 5, + messageContains: [ + // TODO(paulberry): This message text could be better. See + // https://github.com/dart-lang/sdk/issues/62398. + "The constructor 'Foo.a'", + "doesn't have type parameters", + ], + ), + ], + ); + } + + test_messageText_enum() async { + await assertErrorsInCode( + r''' +enum E { + v() +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsEnum, + 18, + 5, + messageContains: [ + 'The enum', + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_extension() async { + await assertErrorsInCode( + r''' +extension E on int { + void foo() {} +} + +void f() { + E(0).foo(); +} +''', + [error(diag.wrongNumberOfTypeArgumentsExtension, 54, 5)], + ); + } + + test_messageText_functionInstantiation_duringConstEvaluation() async { + await assertErrorsInCode( + ''' +void f() {} +const dynamic x = f; +const y = (f); +''', + [ + error( + diag.wrongNumberOfTypeArgumentsAnonymousFunction, + 49, + 13, + messageContains: [ + 'This function', + '1 type parameters', + '2 type arguments', + ], + ), + ], + ); + } + + test_messageText_implicitCallTearoff() async { + await assertErrorsInCode( + ''' +f(C c) { + c; +} +class C { + void call() {} +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsFunction, + 12, + 5, + messageContains: [ + // TODO(paulberry): This message text could be better. See + // https://github.com/dart-lang/sdk/issues/62398. + "The function 'call'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_instantiationOfFunctionTypedExpression() async { + await assertErrorsInCode( + ''' +f(void Function() foo, void Function() bar) { + (1 == 2 ? foo : bar); +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsAnonymousFunction, + 80, + 5, + messageContains: [ + 'This function', + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_localFunction() async { + await assertErrorsInCode( + ''' +f() { + void foo() {} + foo; +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsFunction, + 33, + 5, + messageContains: [ + "The function 'foo'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_namedType() async { + await assertErrorsInCode( + r''' +class A {} +A? a; +''', + [ + error( + diag.wrongNumberOfTypeArguments, + 17, + 5, + messageContains: [ + "The type 'A'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_prefixedConstructorInvocation() async { + newFile('$testPackageLibPath/a.dart', ''' +class Foo { + Foo.bar(); +} +'''); + await assertErrorsInCode( + ''' +import 'a.dart' as p; + +main() { + p.Foo.bar(); +} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsConstructor, + 43, + 5, + messageContains: [ + "The constructor 'p.Foo.bar'", + "doesn't have type parameters", + ], + ), + ], + ); + } + + test_messageText_topLevelFunctionInvocation() async { + await assertErrorsInCode( + ''' +void f() { + g(); +} +void g() {} +''', + [ + error( + diag.wrongNumberOfTypeArgumentsMethod, + 14, + 5, + messageContains: [ + // TODO(paulberry): This message text could be better. See + // https://github.com/dart-lang/sdk/issues/62398. + "The method 'void Function()'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_topLevelFunctionTearoff_const() async { + await assertErrorsInCode( + r''' +void foo(T a, U b) {} +const g = foo; +''', + [ + error( + diag.wrongNumberOfTypeArgumentsFunction, + 41, + 5, + messageContains: [ + "The function 'foo'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_typeInstantiation() async { + await assertErrorsInCode( + ''' +class C {} +var t = C; +''', + [ + error( + diag.wrongNumberOfTypeArguments, + 26, + 5, + messageContains: [ + "The type 'C'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + + test_messageText_typeInstantiation_typedef() async { + await assertErrorsInCode( + ''' +typedef Fn = void Function(T, U); +var t = Fn; +''', + [ + error( + diag.wrongNumberOfTypeArguments, + 50, + 5, + messageContains: [ + "The type 'Fn'", + '2 type parameters', + '1 type arguments', + ], + ), + ], + ); + } + test_metadata_1of0() async { await assertErrorsInCode( r'''