Skip to content

Report arity errors on call target nodes #54443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33922,21 +33922,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function getDiagnosticSpanForCallNode(node: CallExpression, doNotIncludeArguments?: boolean) {
let start: number;
let length: number;
function getDiagnosticSpanForCallNode(node: CallExpression) {
const sourceFile = getSourceFileOfNode(node);

if (isPropertyAccessExpression(node.expression)) {
const nameSpan = getErrorSpanForNode(sourceFile, node.expression.name);
start = nameSpan.start;
length = doNotIncludeArguments ? nameSpan.length : node.end - start;
}
else {
const expressionSpan = getErrorSpanForNode(sourceFile, node.expression);
start = expressionSpan.start;
length = doNotIncludeArguments ? expressionSpan.length : node.end - start;
}
const { start, length } = getErrorSpanForNode(sourceFile, isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression);
return { start, length, sourceFile };
}

Expand Down Expand Up @@ -34915,7 +34903,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
}
if (isCallExpression(errorTarget.parent)) {
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /*doNotIncludeArguments*/ true);
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent);
diagnostic.start = start;
diagnostic.length = length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ arityErrorRelatedSpanBindingPattern.ts(7,1): error TS2554: Expected 3 arguments,
function bar(a, b, [c]): void {}

foo("", 0);
~~~~~~~~~~
~~~
!!! error TS2554: Expected 3 arguments, but got 2.
!!! related TS6211 arityErrorRelatedSpanBindingPattern.ts:1:20: An argument matching this binding pattern was not provided.

bar("", 0);
~~~~~~~~~~
~~~
!!! error TS2554: Expected 3 arguments, but got 2.
!!! related TS6211 arityErrorRelatedSpanBindingPattern.ts:3:20: An argument matching this binding pattern was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/baseCheck.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
}

class D extends C { constructor(public z: number) { super(this.z) } } // too few params
~~~~~~~~~~~~~
~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
!!! related TS6210 baseCheck.ts:1:34: An argument for 'y' was not provided.
~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ blockScopedSameNameFunctionDeclarationES5.ts(16,1): error TS2554: Expected 1 arg
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationES5.ts:1:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ blockScopedSameNameFunctionDeclarationES6.ts(16,1): error TS2554: Expected 1 arg
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationES6.ts:1:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ blockScopedSameNameFunctionDeclarationStrictES5.ts(17,1): error TS2554: Expected
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ blockScopedSameNameFunctionDeclarationStrictES6.ts(17,1): error TS2554: Expected
}
foo(10);
foo(); // not ok
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.
2 changes: 1 addition & 1 deletion tests/baselines/reference/callOverload.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ callOverload.ts(11,10): error TS2556: A spread argument must either have a tuple
!!! error TS2554: Expected 2 arguments, but got 4.
withRest('a', ...n); // no error
withRest();
~~~~~~~~~~
~~~~~~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 callOverload.ts:3:27: An argument for 'a' was not provided.
withRest(...n);
Expand Down
22 changes: 11 additions & 11 deletions tests/baselines/reference/callWithMissingVoid.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.

declare const xAny: X<any>;
xAny.f() // error, any still expects an argument
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

declare const xUnknown: X<unknown>;
xUnknown.f() // error, unknown still expects an argument
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

declare const xNever: X<never>;
xNever.f() // error, never still expects an argument
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

Expand All @@ -56,15 +56,15 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.
new MyPromise<void>(resolve => resolve()); // no error
new MyPromise<void | number>(resolve => resolve()); // no error
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
new MyPromise<never>(resolve => resolve()); // error, `never` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.

Expand All @@ -78,7 +78,7 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.
a(4, "hello"); // ok
a(4, "hello", void 0); // ok
a(4); // not ok
~~~~
~
!!! error TS2554: Expected 2-3 arguments, but got 1.
!!! related TS6210 callWithMissingVoid.ts:42:23: An argument for 'y' was not provided.

Expand All @@ -88,15 +88,15 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.

b(4, "hello", void 0, 2); // ok
b(4, "hello"); // not ok
~~~~~~~~~~~~~
~
!!! error TS2554: Expected 4 arguments, but got 2.
!!! related TS6210 callWithMissingVoid.ts:50:34: An argument for 'z' was not provided.
b(4, "hello", void 0); // not ok
~~~~~~~~~~~~~~~~~~~~~
~
!!! error TS2554: Expected 4 arguments, but got 3.
!!! related TS6210 callWithMissingVoid.ts:50:43: An argument for 'what' was not provided.
b(4); // not ok
~~~~
~
!!! error TS2554: Expected 4 arguments, but got 1.
!!! related TS6210 callWithMissingVoid.ts:50:23: An argument for 'y' was not provided.

Expand All @@ -117,7 +117,7 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.
...args: TS): void;

call((x: number, y: number) => x + y) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS2554: Expected 3 arguments, but got 1.
!!! related TS6236 callWithMissingVoid.ts:73:5: Arguments for the rest parameter 'args' were not provided.
call((x: number, y: number) => x + y, 4, 2) // ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ tsfile.ts(12,4): error TS2554: Expected 1 arguments, but got 0.

// no change in behavior
f2();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:2:21: An argument for 'p' was not provided.
f3();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:3:21: An argument for 'p' was not provided.
f4();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:4:21: An argument for 'p' was not provided.

o2.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o3.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o4.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.

Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ tsfile.ts(12,4): error TS2554: Expected 1 arguments, but got 0.

// new behavior: treat 'undefined', 'unknown', and 'any' as optional in non-strict mode
f2();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:2:21: An argument for 'p' was not provided.
f3();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:3:21: An argument for 'p' was not provided.
f4();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:4:21: An argument for 'p' was not provided.

o2.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o3.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o4.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.

Expand All @@ -63,28 +63,28 @@ tsfile.ts(12,4): error TS2554: Expected 1 arguments, but got 0.

// no change in behavior
f2();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:2:21: An argument for 'p' was not provided.
f3();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:3:21: An argument for 'p' was not provided.
f4();
~~~~
~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:4:21: An argument for 'p' was not provided.

o2.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o3.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
o4.m();
~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ second.ts(17,15): error TS2345: Argument of type 'string' is not assignable to p
class Sql extends Wagon {
constructor() {
super(); // error: not enough arguments
~~~~~~~
~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 first.js:5:16: An argument for 'numberOxen' was not provided.
this.foonly = 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ derivedTypeCallingBaseImplWithOptionalParams.ts(13,3): error TS2554: Expected 1

var y: MyClass = new MyClass();
y.myMethod(); // error
~~~~~~~~~~
~~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 derivedTypeCallingBaseImplWithOptionalParams.ts:5:14: An argument for 'myList' was not provided.
2 changes: 1 addition & 1 deletion tests/baselines/reference/es5DateAPIs.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ es5DateAPIs.ts(1,6): error TS2554: Expected 2-7 arguments, but got 1.

==== es5DateAPIs.ts (1 errors) ====
Date.UTC(2017); // should error
~~~~~~~~~
~~~
!!! error TS2554: Expected 2-7 arguments, but got 1.
!!! related TS6210 lib.es5.d.ts:--:--: An argument for 'monthIndex' was not provided.
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall11.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ functionCall11.ts(6,15): error TS2554: Expected 1-2 arguments, but got 3.
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2554: Expected 1-2 arguments, but got 0.
!!! related TS6210 functionCall11.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall12.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ functionCall12.ts(7,15): error TS2345: Argument of type 'number' is not assignab
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2554: Expected 1-3 arguments, but got 0.
!!! related TS6210 functionCall12.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall13.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ functionCall13.ts(5,5): error TS2345: Argument of type 'number' is not assignabl
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 functionCall13.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall16.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ functionCall16.ts(6,5): error TS2345: Argument of type 'number' is not assignabl
foo('foo');
foo('foo', 'bar');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 functionCall16.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall17.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ functionCall17.ts(6,12): error TS2345: Argument of type 'number' is not assignab
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
foo('foo');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 functionCall17.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall18.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ functionCall18.ts(4,1): error TS2554: Expected 2 arguments, but got 1.
declare function foo<T>(a: T, b: T);
declare function foo(a: {});
foo<string>("hello");
~~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2554: Expected 2 arguments, but got 1.
!!! related TS6210 functionCall18.ts:2:31: An argument for 'b' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ functionCall6.ts(5,1): error TS2554: Expected 1 arguments, but got 0.
~~~~~
!!! error TS2554: Expected 1 arguments, but got 2.
foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 functionCall6.ts:1:14: An argument for 'a' was not provided.

Loading