Skip to content

Commit e9737b8

Browse files
Andaristsandersn
andauthored
Report arity errors on call target nodes (#54443)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 68b9b07 commit e9737b8

File tree

54 files changed

+125
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+125
-137
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33922,21 +33922,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3392233922
}
3392333923
}
3392433924

33925-
function getDiagnosticSpanForCallNode(node: CallExpression, doNotIncludeArguments?: boolean) {
33926-
let start: number;
33927-
let length: number;
33925+
function getDiagnosticSpanForCallNode(node: CallExpression) {
3392833926
const sourceFile = getSourceFileOfNode(node);
33929-
33930-
if (isPropertyAccessExpression(node.expression)) {
33931-
const nameSpan = getErrorSpanForNode(sourceFile, node.expression.name);
33932-
start = nameSpan.start;
33933-
length = doNotIncludeArguments ? nameSpan.length : node.end - start;
33934-
}
33935-
else {
33936-
const expressionSpan = getErrorSpanForNode(sourceFile, node.expression);
33937-
start = expressionSpan.start;
33938-
length = doNotIncludeArguments ? expressionSpan.length : node.end - start;
33939-
}
33927+
const { start, length } = getErrorSpanForNode(sourceFile, isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression);
3394033928
return { start, length, sourceFile };
3394133929
}
3394233930

@@ -34915,7 +34903,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3491534903
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
3491634904
}
3491734905
if (isCallExpression(errorTarget.parent)) {
34918-
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /*doNotIncludeArguments*/ true);
34906+
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent);
3491934907
diagnostic.start = start;
3492034908
diagnostic.length = length;
3492134909
}

tests/baselines/reference/arityErrorRelatedSpanBindingPattern.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ arityErrorRelatedSpanBindingPattern.ts(7,1): error TS2554: Expected 3 arguments,
88
function bar(a, b, [c]): void {}
99

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

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

tests/baselines/reference/baseCheck.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
3030
}
3131

3232
class D extends C { constructor(public z: number) { super(this.z) } } // too few params
33-
~~~~~~~~~~~~~
33+
~~~~~
3434
!!! error TS2554: Expected 2 arguments, but got 1.
3535
!!! related TS6210 baseCheck.ts:1:34: An argument for 'y' was not provided.
3636
~~~~

tests/baselines/reference/blockScopedSameNameFunctionDeclarationES5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ blockScopedSameNameFunctionDeclarationES5.ts(16,1): error TS2554: Expected 1 arg
3333
}
3434
foo(10);
3535
foo(); // not ok - needs number
36-
~~~~~
36+
~~~
3737
!!! error TS2554: Expected 1 arguments, but got 0.
3838
!!! related TS6210 blockScopedSameNameFunctionDeclarationES5.ts:1:14: An argument for 'a' was not provided.

tests/baselines/reference/blockScopedSameNameFunctionDeclarationES6.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ blockScopedSameNameFunctionDeclarationES6.ts(16,1): error TS2554: Expected 1 arg
3333
}
3434
foo(10);
3535
foo(); // not ok - needs number
36-
~~~~~
36+
~~~
3737
!!! error TS2554: Expected 1 arguments, but got 0.
3838
!!! related TS6210 blockScopedSameNameFunctionDeclarationES6.ts:1:14: An argument for 'a' was not provided.

tests/baselines/reference/blockScopedSameNameFunctionDeclarationStrictES5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ blockScopedSameNameFunctionDeclarationStrictES5.ts(17,1): error TS2554: Expected
2929
}
3030
foo(10);
3131
foo(); // not ok - needs number
32-
~~~~~
32+
~~~
3333
!!! error TS2554: Expected 1 arguments, but got 0.
3434
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.
3535
}
3636
foo(10);
3737
foo(); // not ok - needs number
38-
~~~~~
38+
~~~
3939
!!! error TS2554: Expected 1 arguments, but got 0.
4040
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.

tests/baselines/reference/blockScopedSameNameFunctionDeclarationStrictES6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ blockScopedSameNameFunctionDeclarationStrictES6.ts(17,1): error TS2554: Expected
2323
}
2424
foo(10);
2525
foo(); // not ok
26-
~~~~~
26+
~~~
2727
!!! error TS2554: Expected 1 arguments, but got 0.
2828
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.
2929
}
3030
foo(10);
3131
foo(); // not ok - needs number
32-
~~~~~
32+
~~~
3333
!!! error TS2554: Expected 1 arguments, but got 0.
3434
!!! related TS6210 blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.

tests/baselines/reference/callOverload.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ callOverload.ts(11,10): error TS2556: A spread argument must either have a tuple
1919
!!! error TS2554: Expected 2 arguments, but got 4.
2020
withRest('a', ...n); // no error
2121
withRest();
22-
~~~~~~~~~~
22+
~~~~~~~~
2323
!!! error TS2555: Expected at least 1 arguments, but got 0.
2424
!!! related TS6210 callOverload.ts:3:27: An argument for 'a' was not provided.
2525
withRest(...n);

tests/baselines/reference/callWithMissingVoid.errors.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.
2828

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

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

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

@@ -56,15 +56,15 @@ callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1.
5656
new MyPromise<void>(resolve => resolve()); // no error
5757
new MyPromise<void | number>(resolve => resolve()); // no error
5858
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
59-
~~~~~~~~~
59+
~~~~~~~
6060
!!! error TS2554: Expected 1 arguments, but got 0.
6161
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
6262
new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
63-
~~~~~~~~~
63+
~~~~~~~
6464
!!! error TS2554: Expected 1 arguments, but got 0.
6565
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
6666
new MyPromise<never>(resolve => resolve()); // error, `never` arguments cannot be omitted
67-
~~~~~~~~~
67+
~~~~~~~
6868
!!! error TS2554: Expected 1 arguments, but got 0.
6969
!!! related TS6210 callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
7070

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

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

8989
b(4, "hello", void 0, 2); // ok
9090
b(4, "hello"); // not ok
91-
~~~~~~~~~~~~~
91+
~
9292
!!! error TS2554: Expected 4 arguments, but got 2.
9393
!!! related TS6210 callWithMissingVoid.ts:50:34: An argument for 'z' was not provided.
9494
b(4, "hello", void 0); // not ok
95-
~~~~~~~~~~~~~~~~~~~~~
95+
~
9696
!!! error TS2554: Expected 4 arguments, but got 3.
9797
!!! related TS6210 callWithMissingVoid.ts:50:43: An argument for 'what' was not provided.
9898
b(4); // not ok
99-
~~~~
99+
~
100100
!!! error TS2554: Expected 4 arguments, but got 1.
101101
!!! related TS6210 callWithMissingVoid.ts:50:23: An argument for 'y' was not provided.
102102

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

119119
call((x: number, y: number) => x + y) // error
120-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
~~~~
121121
!!! error TS2554: Expected 3 arguments, but got 1.
122122
!!! related TS6236 callWithMissingVoid.ts:73:5: Arguments for the rest parameter 'args' were not provided.
123123
call((x: number, y: number) => x + y, 4, 2) // ok

tests/baselines/reference/callWithMissingVoidUndefinedUnknownAnyInJs(strict=false).errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ tsfile.ts(12,4): error TS2554: Expected 1 arguments, but got 0.
3939

4040
// no change in behavior
4141
f2();
42-
~~~~
42+
~~
4343
!!! error TS2554: Expected 1 arguments, but got 0.
4444
!!! related TS6210 defs.d.ts:2:21: An argument for 'p' was not provided.
4545
f3();
46-
~~~~
46+
~~
4747
!!! error TS2554: Expected 1 arguments, but got 0.
4848
!!! related TS6210 defs.d.ts:3:21: An argument for 'p' was not provided.
4949
f4();
50-
~~~~
50+
~~
5151
!!! error TS2554: Expected 1 arguments, but got 0.
5252
!!! related TS6210 defs.d.ts:4:21: An argument for 'p' was not provided.
5353

5454
o2.m();
55-
~~~
55+
~
5656
!!! error TS2554: Expected 1 arguments, but got 0.
5757
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
5858
o3.m();
59-
~~~
59+
~
6060
!!! error TS2554: Expected 1 arguments, but got 0.
6161
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
6262
o4.m();
63-
~~~
63+
~
6464
!!! error TS2554: Expected 1 arguments, but got 0.
6565
!!! related TS6210 defs.d.ts:6:20: An argument for 'p' was not provided.
6666

0 commit comments

Comments
 (0)