[analyzer] `NOT_ENOUGH_POSITIONAL_ARGUMENTS` To report at the token of the expected positional argument Fixes #50127 Change-Id: I5eb31c6d354fb15d482c2046f7faaa4505658f4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262603 Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart index 2af5b80..bb6f643 100644 --- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart +++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
@@ -78,7 +78,10 @@ CompileTimeErrorCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT: [ DataDriven.new, ], - CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS: [ + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR: [ + DataDriven.new, + ], + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR: [ DataDriven.new, ], CompileTimeErrorCode.UNDEFINED_CLASS: [
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index 9ffb4db..11938e6 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -809,7 +809,13 @@ status: needsEvaluation CompileTimeErrorCode.NOT_BINARY_OPERATOR: status: needsEvaluation -CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS: +CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL: + status: needsEvaluation +CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR: + status: hasFix +CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL: + status: needsEvaluation +CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR: status: hasFix CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD: status: hasFix
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index d110f4f..1542013 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -782,7 +782,10 @@ CompileTimeErrorCode.NOT_A_TYPE: [ ImportLibrary.forType, ], - CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS: [ + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR: [ + DataDriven.new, + ], + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR: [ DataDriven.new, ], CompileTimeErrorCode.TYPE_TEST_WITH_UNDEFINED_NAME: [
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index d839c56..a0f329b 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart
@@ -103,7 +103,9 @@ assert( (arguments ?? const []).length == errorCode.numParameters, 'Message $errorCode requires ${errorCode.numParameters} ' - 'argument(s), but ${(arguments ?? const []).length} argument(s) were ' + 'argument${errorCode.numParameters == 1 ? '' : 's'}, but ' + '${(arguments ?? const []).length} ' + 'argument${(arguments ?? const []).length == 1 ? ' was' : 's were'} ' 'provided'); String problemMessage = formatList(errorCode.problemMessage, arguments); String? correctionTemplate = errorCode.correctionMessage;
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index ff61c2e..9eab0ab 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -3353,12 +3353,47 @@ /// Parameters: /// 0: the expected number of required arguments /// 1: the actual number of positional arguments given - static const CompileTimeErrorCode NOT_ENOUGH_POSITIONAL_ARGUMENTS = - CompileTimeErrorCode( + /// 2: name of the function or method + static const CompileTimeErrorCode + NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL = CompileTimeErrorCode( 'NOT_ENOUGH_POSITIONAL_ARGUMENTS', - "{0} positional argument(s) expected, but {1} found.", + "{0} positional arguments expected by '{2}', but {1} found.", correctionMessage: "Try adding the missing arguments.", hasPublishedDocs: true, + uniqueName: 'NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL', + ); + + /// Parameters: + /// 0: name of the function or method + static const CompileTimeErrorCode + NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR = CompileTimeErrorCode( + 'NOT_ENOUGH_POSITIONAL_ARGUMENTS', + "1 positional argument expected by '{0}', but 0 found.", + correctionMessage: "Try adding the missing argument.", + hasPublishedDocs: true, + uniqueName: 'NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR', + ); + + /// Parameters: + /// 0: the expected number of required arguments + /// 1: the actual number of positional arguments given + static const CompileTimeErrorCode NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL = + CompileTimeErrorCode( + 'NOT_ENOUGH_POSITIONAL_ARGUMENTS', + "{0} positional arguments expected, but {1} found.", + correctionMessage: "Try adding the missing arguments.", + hasPublishedDocs: true, + uniqueName: 'NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL', + ); + + /// No parameters. + static const CompileTimeErrorCode NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR = + CompileTimeErrorCode( + 'NOT_ENOUGH_POSITIONAL_ARGUMENTS', + "1 positional argument expected, but 0 found.", + correctionMessage: "Try adding the missing argument.", + hasPublishedDocs: true, + uniqueName: 'NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR', ); /// Parameters:
diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart index a989b00..6371695 100644 --- a/pkg/analyzer/lib/src/error/error_code_values.g.dart +++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -342,7 +342,10 @@ CompileTimeErrorCode.NOT_ASSIGNED_POTENTIALLY_NON_NULLABLE_LOCAL_VARIABLE, CompileTimeErrorCode.NOT_A_TYPE, CompileTimeErrorCode.NOT_BINARY_OPERATOR, - CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL, + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL, + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR, CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD, CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD_CONSTRUCTOR, CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE,
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart index 7d5ceb5..5b8dd1e 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1815,11 +1815,12 @@ .where((e) => e.isRequiredPositional) .length; if (requiredParameterCount != 0) { - errorReporter.reportErrorForToken( - CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, - node.name, - [requiredParameterCount, 0], - ); + _reportNotEnoughPositionalArguments( + token: node.name, + requiredParameterCount: requiredParameterCount, + actualArgumentCount: 0, + nameNode: node, + errorReporter: errorReporter); } } } @@ -3146,9 +3147,10 @@ int positionalArgumentCount = 0; bool noBlankArguments = true; Expression? firstUnresolvedArgument; + Expression? lastPositionalArgument; for (int i = 0; i < argumentCount; i++) { Expression argument = arguments[i]; - if (argument is! NamedExpressionImpl) { + if (argument is! NamedExpression) { if (argument is SimpleIdentifier && argument.name.isEmpty) { noBlankArguments = false; } @@ -3158,6 +3160,7 @@ } else { firstUnresolvedArgument ??= argument; } + lastPositionalArgument = argument; } } @@ -3196,10 +3199,18 @@ } if (positionalArgumentCount < requiredParameterCount && noBlankArguments) { - errorReporter?.reportErrorForNode( - CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, - argumentList, - [requiredParameterCount, positionalArgumentCount]); + var parent = argumentList.parent; + if (errorReporter != null && parent != null) { + var token = lastPositionalArgument?.endToken.next ?? + argumentList.leftParenthesis.next ?? + argumentList.rightParenthesis; + _reportNotEnoughPositionalArguments( + token: token, + requiredParameterCount: requiredParameterCount, + actualArgumentCount: positionalArgumentCount, + nameNode: parent, + errorReporter: errorReporter); + } } else if (positionalArgumentCount > unnamedParameterCount && noBlankArguments) { ErrorCode errorCode; @@ -3218,6 +3229,78 @@ } return resolvedParameters; } + + /// Report [CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS] or one of + /// its derivatives at the specified [token], considering the name of the + /// [nameNode]. + static void _reportNotEnoughPositionalArguments( + {required Token token, + required int requiredParameterCount, + required int actualArgumentCount, + required AstNode nameNode, + required ErrorReporter errorReporter}) { + String? name; + if (nameNode is InstanceCreationExpression) { + var constructorName = nameNode.constructorName; + name = + constructorName.name?.name ?? '${constructorName.type.name.name}.new'; + } else if (nameNode is SuperConstructorInvocation) { + name = nameNode.constructorName?.name; + if (name == null) { + var staticElement = nameNode.staticElement; + if (staticElement != null) { + name = + '${staticElement.returnType.getDisplayString(withNullability: true)}.new'; + } + } + } else if (nameNode is MethodInvocation) { + name = nameNode.methodName.name; + } else if (nameNode is FunctionExpressionInvocation) { + var function = nameNode.function; + if (function is SimpleIdentifier) { + name = function.name; + } + } else if (nameNode is EnumConstantArguments) { + var parent = nameNode.parent; + if (parent is EnumConstantDeclaration) { + var declaredElement = parent.declaredElement; + if (declaredElement is VariableElement) { + name = declaredElement.type.getDisplayString(withNullability: true); + } + } + } else if (nameNode is EnumConstantDeclaration) { + var declaredElement = nameNode.declaredElement; + if (declaredElement is VariableElement) { + name = declaredElement.type.getDisplayString(withNullability: true); + } + } else if (nameNode is Annotation) { + var nameNodeName = nameNode.name; + name = nameNodeName is PrefixedIdentifier + ? nameNodeName.identifier.name + : '${nameNodeName.name}.new'; + } else { + throw UnimplementedError('(${nameNode.runtimeType}) $nameNode'); + } + + var isPlural = requiredParameterCount - actualArgumentCount > 1; + var arguments = <Object>[]; + if (isPlural) { + arguments.add(requiredParameterCount); + arguments.add(actualArgumentCount); + } + ErrorCode errorCode; + if (name == null) { + errorCode = isPlural + ? CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL + : CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR; + } else { + errorCode = isPlural + ? CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL + : CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR; + arguments.add(name); + } + errorReporter.reportErrorForToken(errorCode, token, arguments); + } } /// Override of [ResolverVisitorForMigration] that invokes methods of
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index 39c228f..d33ed6a 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml
@@ -10275,14 +10275,12 @@ ```dart var a = 5 - 3; ``` - NOT_ENOUGH_POSITIONAL_ARGUMENTS: - problemMessage: "{0} positional argument(s) expected, but {1} found." - correctionMessage: Try adding the missing arguments. + NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR: + sharedName: NOT_ENOUGH_POSITIONAL_ARGUMENTS + problemMessage: "1 positional argument expected, but 0 found." + correctionMessage: Try adding the missing argument. hasPublishedDocs: true - comment: |- - Parameters: - 0: the expected number of required arguments - 1: the actual number of positional arguments given + comment: No parameters. documentation: |- #### Description @@ -10298,7 +10296,7 @@ ```dart void f(int a, int b) {} void g() { - f[!(0)!]; + f(0[!)!]; } ``` @@ -10312,6 +10310,33 @@ f(0, 1); } ``` + NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL: + sharedName: NOT_ENOUGH_POSITIONAL_ARGUMENTS + problemMessage: "{0} positional arguments expected, but {1} found." + correctionMessage: Try adding the missing arguments. + hasPublishedDocs: true + comment: |- + Parameters: + 0: the expected number of required arguments + 1: the actual number of positional arguments given + NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR: + sharedName: NOT_ENOUGH_POSITIONAL_ARGUMENTS + problemMessage: "1 positional argument expected by '{0}', but 0 found." + correctionMessage: Try adding the missing argument. + hasPublishedDocs: true + comment: |- + Parameters: + 0: name of the function or method + NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL: + sharedName: NOT_ENOUGH_POSITIONAL_ARGUMENTS + problemMessage: "{0} positional arguments expected by '{2}', but {1} found." + correctionMessage: Try adding the missing arguments. + hasPublishedDocs: true + comment: |- + Parameters: + 0: the expected number of required arguments + 1: the actual number of positional arguments given + 2: name of the function or method NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD: problemMessage: "Non-nullable instance field '{0}' must be initialized." correctionMessage: "Try adding an initializer expression, or a generative constructor that initializes it, or mark it 'late'."
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/function_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/function_test.dart index 77f3d6b..3f56554 100644 --- a/pkg/analyzer/test/src/dart/resolution/type_inference/function_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/type_inference/function_test.dart
@@ -53,7 +53,8 @@ foo(1); } ''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 37, 3), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 39, 1), ]); assertTypeArgumentTypes( findNode.methodInvocation('foo('),
diff --git a/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart b/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart index 02d46a3..e3baa70 100644 --- a/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart
@@ -50,7 +50,8 @@ @FfiNative() external int foo(); ''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 30, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 31, 1), ]); }
diff --git a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart index 78a8782..adcad6b 100644 --- a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart
@@ -15,6 +15,53 @@ @reflectiveTest class NotEnoughPositionalArgumentsTest extends PubPackageResolutionTest { + test_annotation_named() async { + await assertErrorsInCode(r''' +class A { + const A.named(int p); +} +@A.named() +void f() { +} +''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 45, 1, + messageContains: ["expected by 'named'"]), + ]); + } + + test_annotation_withArgumentList() async { + await assertErrorsInCode(r''' +class A { + const A(int p); +} +@A() +void f() { +} +''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 33, 1, + messageContains: ["expected by 'A.new'"]), + ]); + } + + test_annotation_withoutArgumentList() async { + await assertErrorsInCode(r''' +class A { + const A(int p); +} +const a = A(); +@a +void f() { +} +''', [ + error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 40, 3), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 42, 1, + messageContains: ["expected by 'A.new'"]), + ]); + } + test_const() async { await assertErrorsInCode(r''' class A { @@ -25,7 +72,9 @@ } ''', [ error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 9), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 48, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 49, 1, + messageContains: ["expected by 'A.new'"]), ]); } @@ -39,7 +88,8 @@ } ''', [ error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 13), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 48, 6), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 49, 1), error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 49, 1), ]); } @@ -53,7 +103,56 @@ const B() : super(); } ''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 69, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 70, 1, + messageContains: ["expected by 'A.new'"]), + ]); + } + + test_const_super_named() async { + await assertErrorsInCode(r''' +class A { + const A.named(int p); +} +class B extends A { + const B() : super.named(); +} +''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 82, 1, + messageContains: ["expected by 'named'"]), + ]); + } + + test_constructor_named() async { + await assertErrorsInCode(r''' +class A { + A.named(int x, int y, {int? n}); +} + +void f() { + A.named(5, n: 1); +} +''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 70, 1, + messageContains: ["expected by 'named'"]), + ]); + } + + test_constructor_positionalAndNamed() async { + await assertErrorsInCode(r''' +class A { + A(int x, int y, {int? n}); +} + +void f() { + A(5, n: 1); +} +''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 58, 1, + messageContains: ["expected by 'A.new'"]), ]); } @@ -65,7 +164,9 @@ } ''', [ error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 3), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 12, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 13, 1, + messageContains: ["expected by 'E'"]), ]); } @@ -77,16 +178,28 @@ } ''', [ error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 1), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 11, 1), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 11, 1, + messageContains: ["expected by 'E'"]), ]); } - test_functionExpression() async { + test_functionExpression_plural() async { + await assertErrorsInCode(''' +main() { + (int x, int y) {} (); +}''', [ + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_PLURAL, 30, 1), + ]); + } + + test_functionExpression_singular() async { await assertErrorsInCode(''' main() { (int x) {} (); }''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 22, 2), + error( + CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_SINGULAR, 23, 1), ]); } @@ -96,7 +209,9 @@ main() { f(); }''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 34, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_PLURAL, + 35, 1, + messageContains: ["expected by 'f'"]), ]); } @@ -107,7 +222,9 @@ main() { getter(); }''', [ - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 65, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 66, 1, + messageContains: ["expected by 'getter'"]), ]); }
diff --git a/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart b/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart index 88a67db..016d107 100644 --- a/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart +++ b/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart
@@ -41,7 +41,8 @@ } ''', [ error(FfiCode.PACKED_ANNOTATION_ALIGNMENT, 20, 9), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 27, 2), + error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, + 28, 1), ]); }
diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index 028dd86..2cdac0d 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md
@@ -13280,7 +13280,13 @@ ### not_enough_positional_arguments -_{0} positional argument(s) expected, but {1} found._ +_1 positional argument expected by '{0}', but 0 found._ + +_1 positional argument expected, but 0 found._ + +_{0} positional arguments expected by '{2}', but {1} found._ + +_{0} positional arguments expected, but {1} found._ #### Description @@ -13296,7 +13302,7 @@ {% prettify dart tag=pre+code %} void f(int a, int b) {} void g() { - f[!(0)!]; + f(0[!)!]; } {% endprettify %}
diff --git a/tests/language/argument/not_enough_positional_arguments_test.dart b/tests/language/argument/not_enough_positional_arguments_test.dart index 9ebd09f..d535ca6 100644 --- a/tests/language/argument/not_enough_positional_arguments_test.dart +++ b/tests/language/argument/not_enough_positional_arguments_test.dart
@@ -23,8 +23,9 @@ class C extends A { C() : super.test(b: 1) - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER @@ -39,34 +40,39 @@ class E extends D { E() : super.test(b: 1) - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. ; } main() { new A.test(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER new B(); new C(); new D.test(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. new E(); foo(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER bar(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language/call/method_implicit_invoke_local_test.dart b/tests/language/call/method_implicit_invoke_local_test.dart index 0e15829..3950e1b 100644 --- a/tests/language/call/method_implicit_invoke_local_test.dart +++ b/tests/language/call/method_implicit_invoke_local_test.dart
@@ -28,8 +28,9 @@ Expect.equals(d2(1), 2); // Cannot invoke with the wrong signature. c2(); - //^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + //^^ // [cfe] Too few positional arguments: 1 required, 0 given. c2(3, 4); // ^
diff --git a/tests/language/compile_time_constant/arguments_test.dart b/tests/language/compile_time_constant/arguments_test.dart index 5640876..845239f 100644 --- a/tests/language/compile_time_constant/arguments_test.dart +++ b/tests/language/compile_time_constant/arguments_test.dart
@@ -11,8 +11,9 @@ main() { const A(1); const A(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. const A(1, 2); // ^
diff --git a/tests/language/constructor/bodyless_wrong_arg_test.dart b/tests/language/constructor/bodyless_wrong_arg_test.dart index 51f16f5..b3560d2 100644 --- a/tests/language/constructor/bodyless_wrong_arg_test.dart +++ b/tests/language/constructor/bodyless_wrong_arg_test.dart
@@ -11,8 +11,9 @@ const C(String s) // Call super constructor with wrong argument count. : super(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language/constructor/call_wrong_argument_count_test.dart b/tests/language/constructor/call_wrong_argument_count_test.dart index 4830bcd..bb68d7e 100644 --- a/tests/language/constructor/call_wrong_argument_count_test.dart +++ b/tests/language/constructor/call_wrong_argument_count_test.dart
@@ -9,7 +9,8 @@ main() { new Stockhorn(1); new Stockhorn(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language/constructor/constructor13_test.dart b/tests/language/constructor/constructor13_test.dart index 24b8841..40158ad 100644 --- a/tests/language/constructor/constructor13_test.dart +++ b/tests/language/constructor/constructor13_test.dart
@@ -11,8 +11,9 @@ main() { new Klass(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. new Klass(1); new Klass(1, 2);
diff --git a/tests/language/parameter/bad_named2_test.dart b/tests/language/parameter/bad_named2_test.dart index 131909b..f63a84c 100644 --- a/tests/language/parameter/bad_named2_test.dart +++ b/tests/language/parameter/bad_named2_test.dart
@@ -16,8 +16,9 @@ // No formal parameter named b. np.foo(b: 25); - // ^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
diff --git a/tests/language/parameter/bad_named_parameters_test.dart b/tests/language/parameter/bad_named_parameters_test.dart index 79c40c1..6105c19 100644 --- a/tests/language/parameter/bad_named_parameters_test.dart +++ b/tests/language/parameter/bad_named_parameters_test.dart
@@ -49,7 +49,8 @@ // Too few parameters. np.f42(b: 25); - // ^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language/parameter/named_aggregated_test.dart b/tests/language/parameter/named_aggregated_test.dart index 1ed33f2..0760e9f 100644 --- a/tests/language/parameter/named_aggregated_test.dart +++ b/tests/language/parameter/named_aggregated_test.dart
@@ -50,8 +50,9 @@ // Expect compile-time error due to missing positional argument. NamedParametersAggregatedTests.F31(b: 25, c: 35); - // ^^^^^^^^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. new TypeTester<Callback>();
diff --git a/tests/language_2/argument/not_enough_positional_arguments_test.dart b/tests/language_2/argument/not_enough_positional_arguments_test.dart index 2a0403a..61d3de4 100644 --- a/tests/language_2/argument/not_enough_positional_arguments_test.dart +++ b/tests/language_2/argument/not_enough_positional_arguments_test.dart
@@ -25,8 +25,9 @@ class C extends A { C() : super.test(b: 1) - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER @@ -41,34 +42,39 @@ class E extends D { E() : super.test(b: 1) - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. ; } main() { new A.test(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER new B(); new C(); new D.test(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. new E(); foo(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER bar(b: 1); - // ^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language_2/call/method_implicit_invoke_local_test.dart b/tests/language_2/call/method_implicit_invoke_local_test.dart index f304eb4..0f5b520 100644 --- a/tests/language_2/call/method_implicit_invoke_local_test.dart +++ b/tests/language_2/call/method_implicit_invoke_local_test.dart
@@ -30,8 +30,9 @@ Expect.equals(d2(1), 2); // Cannot invoke with the wrong signature. c2(); - //^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + //^^ // [cfe] Too few positional arguments: 1 required, 0 given. c2(3, 4); // ^
diff --git a/tests/language_2/compile_time_constant/arguments_test.dart b/tests/language_2/compile_time_constant/arguments_test.dart index 53083eb..fc30343 100644 --- a/tests/language_2/compile_time_constant/arguments_test.dart +++ b/tests/language_2/compile_time_constant/arguments_test.dart
@@ -13,8 +13,9 @@ main() { const A(1); const A(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. const A(1, 2); // ^
diff --git a/tests/language_2/constructor/bodyless_wrong_arg_test.dart b/tests/language_2/constructor/bodyless_wrong_arg_test.dart index acbdde1..a286ddb 100644 --- a/tests/language_2/constructor/bodyless_wrong_arg_test.dart +++ b/tests/language_2/constructor/bodyless_wrong_arg_test.dart
@@ -13,8 +13,9 @@ const C(String s) // Call super constructor with wrong argument count. : super(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language_2/constructor/call_wrong_argument_count_test.dart b/tests/language_2/constructor/call_wrong_argument_count_test.dart index 1dbb91a..136e68c 100644 --- a/tests/language_2/constructor/call_wrong_argument_count_test.dart +++ b/tests/language_2/constructor/call_wrong_argument_count_test.dart
@@ -11,7 +11,8 @@ main() { new Stockhorn(1); new Stockhorn(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language_2/constructor/constructor13_test.dart b/tests/language_2/constructor/constructor13_test.dart index b7051ea..59d051a 100644 --- a/tests/language_2/constructor/constructor13_test.dart +++ b/tests/language_2/constructor/constructor13_test.dart
@@ -13,8 +13,9 @@ main() { new Klass(); - // ^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^ // [cfe] Too few positional arguments: 1 required, 0 given. new Klass(1); new Klass(1, 2);
diff --git a/tests/language_2/parameter/bad_named2_test.dart b/tests/language_2/parameter/bad_named2_test.dart index 7198a8a..0a32d4b 100644 --- a/tests/language_2/parameter/bad_named2_test.dart +++ b/tests/language_2/parameter/bad_named2_test.dart
@@ -18,8 +18,9 @@ // No formal parameter named b. np.foo(b: 25); - // ^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. // ^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
diff --git a/tests/language_2/parameter/bad_named_parameters_test.dart b/tests/language_2/parameter/bad_named_parameters_test.dart index 94e841b..05c4859 100644 --- a/tests/language_2/parameter/bad_named_parameters_test.dart +++ b/tests/language_2/parameter/bad_named_parameters_test.dart
@@ -51,7 +51,8 @@ // Too few parameters. np.f42(b: 25); - // ^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. }
diff --git a/tests/language_2/parameter/named_aggregated_test.dart b/tests/language_2/parameter/named_aggregated_test.dart index 485af9b..b7150b7 100644 --- a/tests/language_2/parameter/named_aggregated_test.dart +++ b/tests/language_2/parameter/named_aggregated_test.dart
@@ -52,8 +52,9 @@ // Expect compile-time error due to missing positional argument. NamedParametersAggregatedTests.F31(b: 25, c: 35); - // ^^^^^^^^^^^^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + // ^^^^^^^^^^^^^^ // [cfe] Too few positional arguments: 1 required, 0 given. new TypeTester<Callback>();
diff --git a/tests/lib/html/js_function_getter_trust_types/compile_test.dart b/tests/lib/html/js_function_getter_trust_types/compile_test.dart index 29f8669..a9ae402 100644 --- a/tests/lib/html/js_function_getter_trust_types/compile_test.dart +++ b/tests/lib/html/js_function_getter_trust_types/compile_test.dart
@@ -41,7 +41,7 @@ foo.bar.add(4); // ^ // [cfe] Error: Too few positional arguments: 2 required, 1 given. - // ^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS foo.bar.add(4, 5, 10);
diff --git a/tests/lib_2/html/js_function_getter_trust_types/compile_test.dart b/tests/lib_2/html/js_function_getter_trust_types/compile_test.dart index b865351..2498028 100644 --- a/tests/lib_2/html/js_function_getter_trust_types/compile_test.dart +++ b/tests/lib_2/html/js_function_getter_trust_types/compile_test.dart
@@ -43,7 +43,7 @@ foo.bar.add(4); // ^ // [cfe] Error: Too few positional arguments: 2 required, 1 given. - // ^^^ + // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS foo.bar.add(4, 5, 10);