Skip to content

Commit 01c86c7

Browse files
sandersnweswigham
andauthored
Fix get candidate for overload failure checking (#36744)
* getCandidateForOverloadFailure:call resolveUntypedCall This re-adds the missed errors and marks as used missed nodes from the user and RWC baselines. * Update baselines and remove new test It was redundant with the old tests * Defer resolveUntypedCall on resolution failure to give priority to parameter types fixed by overload signatures Co-authored-by: Wesley Wigham <[email protected]>
1 parent 6f079a4 commit 01c86c7

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22600,6 +22600,7 @@ namespace ts {
2260022600

2260122601
function checkJsxSelfClosingElementDeferred(node: JsxSelfClosingElement) {
2260222602
checkJsxOpeningLikeElementOrOpeningFragment(node);
22603+
resolveUntypedCall(node); // ensure type arguments and parameters are typechecked, even if there is an arity error
2260322604
}
2260422605

2260522606
function checkJsxSelfClosingElement(node: JsxSelfClosingElement, _checkMode: CheckMode | undefined): Type {
@@ -24987,14 +24988,14 @@ namespace ts {
2498724988
}
2498824989

2498924990
// No signature was applicable. We have already reported the errors for the invalid signature.
24990-
// If this is a type resolution session, e.g. Language Service, try to get better information than anySignature.
2499124991
function getCandidateForOverloadFailure(
2499224992
node: CallLikeExpression,
2499324993
candidates: Signature[],
2499424994
args: readonly Expression[],
2499524995
hasCandidatesOutArray: boolean,
2499624996
): Signature {
2499724997
Debug.assert(candidates.length > 0); // Else should not have called this.
24998+
checkNodeDeferred(node);
2499824999
// Normally we will combine overloads. Skip this if they have type parameters since that's hard to combine.
2499925000
// Don't do this if there is a `candidatesOutArray`,
2500025001
// because then we want the chosen best candidate to be one of the overloads, not a combination.
@@ -33913,6 +33914,16 @@ namespace ts {
3391333914
currentNode = node;
3391433915
instantiationCount = 0;
3391533916
switch (node.kind) {
33917+
case SyntaxKind.CallExpression:
33918+
case SyntaxKind.NewExpression:
33919+
case SyntaxKind.TaggedTemplateExpression:
33920+
case SyntaxKind.Decorator:
33921+
case SyntaxKind.JsxOpeningElement:
33922+
// These node kinds are deferred checked when overload resolution fails
33923+
// To save on work, we ensure the arguments are checked just once, in
33924+
// a deferred way
33925+
resolveUntypedCall(node as CallLikeExpression);
33926+
break;
3391633927
case SyntaxKind.FunctionExpression:
3391733928
case SyntaxKind.ArrowFunction:
3391833929
case SyntaxKind.MethodDeclaration:

tests/baselines/reference/baseCheck.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
tests/cases/compiler/baseCheck.ts(9,18): error TS2552: Cannot find name 'loc'. Did you mean 'ELoc'?
22
tests/cases/compiler/baseCheck.ts(17,53): error TS2554: Expected 2 arguments, but got 1.
3+
tests/cases/compiler/baseCheck.ts(17,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
34
tests/cases/compiler/baseCheck.ts(18,62): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
45
tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'.
6+
tests/cases/compiler/baseCheck.ts(19,68): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
57
tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'.
68
tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'.
79
tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
810

911

10-
==== tests/cases/compiler/baseCheck.ts (7 errors) ====
12+
==== tests/cases/compiler/baseCheck.ts (9 errors) ====
1113
class C { constructor(x: number, y: number) { } }
1214
class ELoc extends C {
1315
constructor(x: number) {
@@ -31,12 +33,16 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
3133
~~~~~~~~~~~~~
3234
!!! error TS2554: Expected 2 arguments, but got 1.
3335
!!! related TS6210 tests/cases/compiler/baseCheck.ts:1:34: An argument for 'y' was not provided.
36+
~~~~
37+
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
3438
class E extends C { constructor(public z: number) { super(0, this.z) } }
3539
~~~~
3640
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
3741
class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type
3842
~~~~~~~
3943
!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'.
44+
~~~~
45+
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
4046

4147
function f() {
4248
if (x<10) {
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
tests/cases/compiler/grammarAmbiguities1.ts(8,3): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
2+
tests/cases/compiler/grammarAmbiguities1.ts(8,10): error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
13
tests/cases/compiler/grammarAmbiguities1.ts(8,10): error TS2554: Expected 1 arguments, but got 2.
4+
tests/cases/compiler/grammarAmbiguities1.ts(9,3): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
5+
tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
26
tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2554: Expected 1 arguments, but got 2.
37

48

5-
==== tests/cases/compiler/grammarAmbiguities1.ts (2 errors) ====
9+
==== tests/cases/compiler/grammarAmbiguities1.ts (6 errors) ====
610
class A { foo() { } }
711
class B { bar() { }}
812
function f(x) { return x; }
@@ -11,9 +15,17 @@ tests/cases/compiler/grammarAmbiguities1.ts(9,10): error TS2554: Expected 1 argu
1115

1216
f(g<A, B>(7));
1317
f(g < A, B > 7);
18+
~~~~~
19+
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
20+
~~~~~
21+
!!! error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
1422
~~~~~
1523
!!! error TS2554: Expected 1 arguments, but got 2.
1624
f(g < A, B > +(7));
25+
~~~~~
26+
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: any) => any' and 'typeof A'.
27+
~~~~~~~~
28+
!!! error TS2365: Operator '>' cannot be applied to types 'typeof B' and 'number'.
1729
~~~~~~~~
1830
!!! error TS2554: Expected 1 arguments, but got 2.
1931

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,16): error TS2556: Expected 0 arguments, but got 1 or more.
2+
tests/cases/compiler/noImplicitAnyLoopCrash.ts(4,19): error TS2461: Type 'number' is not an array type.
23

34

4-
==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (1 errors) ====
5+
==== tests/cases/compiler/noImplicitAnyLoopCrash.ts (2 errors) ====
56
let foo = () => {};
67
let bar;
78
while (1) {
89
bar = ~foo(...bar);
910
~~~~~~
1011
!!! error TS2556: Expected 0 arguments, but got 1 or more.
12+
~~~
13+
!!! error TS2461: Type 'number' is not an array type.
1114
}
1215

tests/baselines/reference/undeclaredModuleError.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
tests/cases/compiler/undeclaredModuleError.ts(1,21): error TS2307: Cannot find module 'fs'.
22
tests/cases/compiler/undeclaredModuleError.ts(8,29): error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: any, name: string) => boolean'.
33
Type 'void' is not assignable to type 'boolean'.
4+
tests/cases/compiler/undeclaredModuleError.ts(11,41): error TS2304: Cannot find name 'IDoNotExist'.
45

56

6-
==== tests/cases/compiler/undeclaredModuleError.ts (2 errors) ====
7+
==== tests/cases/compiler/undeclaredModuleError.ts (3 errors) ====
78
import fs = require('fs');
89
~~~~
910
!!! error TS2307: Cannot find module 'fs'.
@@ -20,6 +21,8 @@ tests/cases/compiler/undeclaredModuleError.ts(8,29): error TS2345: Argument of t
2021
} , (error: Error, files: {}[]) => {
2122
files.forEach((file) => {
2223
var fullPath = join(IDoNotExist);
24+
~~~~~~~~~~~
25+
!!! error TS2304: Cannot find name 'IDoNotExist'.
2326
} );
2427
} );
2528
} );

0 commit comments

Comments
 (0)