mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[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>
This commit is contained in:
parent
b62cfff200
commit
0b5d908221
|
@ -78,7 +78,10 @@ class BulkFixProcessor {
|
|||
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: [
|
||||
|
|
|
@ -809,7 +809,13 @@ CompileTimeErrorCode.NOT_ASSIGNED_POTENTIALLY_NON_NULLABLE_LOCAL_VARIABLE:
|
|||
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
|
||||
|
|
|
@ -782,7 +782,10 @@ class FixProcessor extends BaseProcessor {
|
|||
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: [
|
||||
|
|
|
@ -103,7 +103,9 @@ class AnalysisError implements Diagnostic {
|
|||
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;
|
||||
|
|
|
@ -3353,12 +3353,47 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
|
|||
/// 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:
|
||||
|
|
|
@ -342,7 +342,10 @@ const List<ErrorCode> errorCodeValues = [
|
|||
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,
|
||||
|
|
|
@ -1815,11 +1815,12 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
.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 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
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 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
} else {
|
||||
firstUnresolvedArgument ??= argument;
|
||||
}
|
||||
lastPositionalArgument = argument;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3196,10 +3199,18 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
}
|
||||
|
||||
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 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
}
|
||||
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
|
||||
|
|
|
@ -10275,14 +10275,12 @@ CompileTimeErrorCode:
|
|||
```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 @@ CompileTimeErrorCode:
|
|||
```dart
|
||||
void f(int a, int b) {}
|
||||
void g() {
|
||||
f[!(0)!];
|
||||
f(0[!)!];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -10312,6 +10310,33 @@ CompileTimeErrorCode:
|
|||
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'."
|
||||
|
|
|
@ -53,7 +53,8 @@ f() {
|
|||
foo(1);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 37, 3),
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
|
||||
39, 1),
|
||||
]);
|
||||
assertTypeArgumentTypes(
|
||||
findNode.methodInvocation('foo('),
|
||||
|
|
|
@ -50,7 +50,8 @@ import 'dart:ffi';
|
|||
@FfiNative()
|
||||
external int foo();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 30, 2),
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
|
||||
31, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,53 @@ main() {
|
|||
|
||||
@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 @@ main() {
|
|||
}
|
||||
''', [
|
||||
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 @@ main() {
|
|||
}
|
||||
''', [
|
||||
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 @@ class B extends A {
|
|||
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 @@ enum E {
|
|||
}
|
||||
''', [
|
||||
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 @@ enum E {
|
|||
}
|
||||
''', [
|
||||
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 @@ f(int a, String b) {}
|
|||
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 @@ Getter getter = (x) => x;
|
|||
main() {
|
||||
getter();
|
||||
}''', [
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 65, 2),
|
||||
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
|
||||
66, 1,
|
||||
messageContains: ["expected by 'getter'"]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ class C extends Struct {
|
|||
}
|
||||
''', [
|
||||
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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -13280,7 +13280,13 @@ var a = 5 - 3;
|
|||
|
||||
### 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 @@ required parameters, but only one argument is provided:
|
|||
{% prettify dart tag=pre+code %}
|
||||
void f(int a, int b) {}
|
||||
void g() {
|
||||
f[!(0)!];
|
||||
f(0[!)!];
|
||||
}
|
||||
{% endprettify %}
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ class B {
|
|||
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 D {
|
|||
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.
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ main() {
|
|||
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);
|
||||
// ^
|
||||
|
|
|
@ -11,8 +11,9 @@ class A {
|
|||
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);
|
||||
// ^
|
||||
|
|
|
@ -11,8 +11,9 @@ class C extends Base {
|
|||
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.
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ class Stockhorn {
|
|||
main() {
|
||||
new Stockhorn(1);
|
||||
new Stockhorn();
|
||||
// ^^
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// ^^
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ class Klass {
|
|||
|
||||
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);
|
||||
|
|
|
@ -16,8 +16,9 @@ main() {
|
|||
|
||||
// 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
|
||||
|
|
|
@ -49,7 +49,8 @@ main() {
|
|||
|
||||
// Too few parameters.
|
||||
np.f42(b: 25);
|
||||
// ^^^^^^^
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// ^^^^^^^
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
}
|
||||
|
|
|
@ -50,8 +50,9 @@ main() {
|
|||
|
||||
// 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>();
|
||||
|
|
|
@ -25,8 +25,9 @@ class B {
|
|||
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 D {
|
|||
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.
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@ main() {
|
|||
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);
|
||||
// ^
|
||||
|
|
|
@ -13,8 +13,9 @@ class A {
|
|||
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);
|
||||
// ^
|
||||
|
|
|
@ -13,8 +13,9 @@ class C extends Base {
|
|||
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.
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ class Stockhorn {
|
|||
main() {
|
||||
new Stockhorn(1);
|
||||
new Stockhorn();
|
||||
// ^^
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// ^^
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ class Klass {
|
|||
|
||||
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);
|
||||
|
|
|
@ -18,8 +18,9 @@ main() {
|
|||
|
||||
// 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
|
||||
|
|
|
@ -51,7 +51,8 @@ main() {
|
|||
|
||||
// Too few parameters.
|
||||
np.f42(b: 25);
|
||||
// ^^^^^^^
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// ^^^^^^^
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
}
|
||||
|
|
|
@ -52,8 +52,9 @@ main() {
|
|||
|
||||
// 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>();
|
||||
|
|
|
@ -41,7 +41,7 @@ main() {
|
|||
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);
|
||||
|
|
|
@ -43,7 +43,7 @@ main() {
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue