Skip to content

Always call getCandidateForOverloadFailure #28564

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19952,7 +19952,7 @@ namespace ts {
}
}

return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);

function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false) {
candidateForArgumentError = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ baz(array); // Error
baz(["string", 1, true, ...array]); // Error
>baz(["string", 1, true, ...array]) : void
>baz : (x: [string, number, boolean]) => void
>["string", 1, true, ...array] : (string | number | boolean)[]
>["string", 1, true, ...array] : [string, number, true, ...(string | number | boolean)[]]
>"string" : "string"
>1 : 1
>true : true
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayAssignmentTest3.types
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class a {


var xx = new a(null, 7, new B());
>xx : any
>new a(null, 7, new B()) : any
>xx : a
>new a(null, 7, new B()) : a
>a : typeof a
>null : null
>7 : 7
Expand Down
8 changes: 1 addition & 7 deletions tests/baselines/reference/baseCheck.errors.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
tests/cases/compiler/baseCheck.ts(9,18): error TS2552: Cannot find name 'loc'. Did you mean 'ELoc'?
tests/cases/compiler/baseCheck.ts(17,53): error TS2554: Expected 2 arguments, but got 1.
tests/cases/compiler/baseCheck.ts(17,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(18,62): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'.
tests/cases/compiler/baseCheck.ts(19,68): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'.
tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'.
tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.


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

function f() {
if (x<10) {
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/bigintWithLib.types
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ bigIntArray = new BigInt64Array([1n, 2n, 3n]);
>3n : 3n

bigIntArray = new BigInt64Array([1, 2, 3]); // should error
>bigIntArray = new BigInt64Array([1, 2, 3]) : any
>bigIntArray = new BigInt64Array([1, 2, 3]) : BigInt64Array
>bigIntArray : BigInt64Array
>new BigInt64Array([1, 2, 3]) : any
>new BigInt64Array([1, 2, 3]) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
Expand Down Expand Up @@ -174,9 +174,9 @@ bigUintArray = new BigUint64Array([1n, 2n, 3n]);
>3n : 3n

bigUintArray = new BigUint64Array([1, 2, 3]); // should error
>bigUintArray = new BigUint64Array([1, 2, 3]) : any
>bigUintArray = new BigUint64Array([1, 2, 3]) : BigUint64Array
>bigUintArray : BigUint64Array
>new BigUint64Array([1, 2, 3]) : any
>new BigUint64Array([1, 2, 3]) : BigUint64Array
>BigUint64Array : BigUint64ArrayConstructor
>[1, 2, 3] : number[]
>1 : 1
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/bigintWithoutLib.types
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let stringVal: string = bigintVal.toString(); // should not error - bigintVal in
>toString : () => string

stringVal = bigintVal.toString(2); // should error - bigintVal inferred as {}
>stringVal = bigintVal.toString(2) : any
>stringVal = bigintVal.toString(2) : string
>stringVal : string
>bigintVal.toString(2) : string
>bigintVal.toString : () => string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function foo(a: number) {
>foo : { (): void; (): void; }

foo(10); // not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10
}
Expand All @@ -29,12 +29,12 @@ function foo(a: number) {
>foo : { (): void; (): void; }

foo(10); // not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10
}
foo(10); // not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function foo(a: number) {
>foo : { (): void; (): void; }

foo(10); // not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10
}
Expand All @@ -29,12 +29,12 @@ function foo(a: number) {
>foo : { (): void; (): void; }

foo(10);// not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10
}
foo(10); // not ok
>foo(10) : any
>foo(10) : void
>foo : { (): void; (): void; }
>10 : 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function f<T, U>(x: T, y: U): T { return null; }
>null : null

var r1 = f<number>(1, '');
>r1 : any
>f<number>(1, '') : any
>r1 : number
>f<number>(1, '') : number
>f : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""

var r1b = f<number, string, number>(1, '');
>r1b : any
>f<number, string, number>(1, '') : any
>r1b : number
>f<number, string, number>(1, '') : number
>f : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""
Expand All @@ -30,15 +30,15 @@ var f2 = <T, U>(x: T, y: U): T => { return null; }
>null : null

var r2 = f2<number>(1, '');
>r2 : any
>f2<number>(1, '') : any
>r2 : number
>f2<number>(1, '') : number
>f2 : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""

var r2b = f2<number, string, number>(1, '');
>r2b : any
>f2<number, string, number>(1, '') : any
>r2b : number
>f2<number, string, number>(1, '') : number
>f2 : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""
Expand All @@ -49,15 +49,15 @@ var f3: { <T, U>(x: T, y: U): T; }
>y : U

var r3 = f3<number>(1, '');
>r3 : any
>f3<number>(1, '') : any
>r3 : number
>f3<number>(1, '') : number
>f3 : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""

var r3b = f3<number, string, number>(1, '');
>r3b : any
>f3<number, string, number>(1, '') : any
>r3b : number
>f3<number, string, number>(1, '') : number
>f3 : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""
Expand All @@ -75,8 +75,8 @@ class C {
}
}
var r4 = (new C()).f<number>(1, '');
>r4 : any
>(new C()).f<number>(1, '') : any
>r4 : number
>(new C()).f<number>(1, '') : number
>(new C()).f : <T, U>(x: T, y: U) => T
>(new C()) : C
>new C() : C
Expand All @@ -86,8 +86,8 @@ var r4 = (new C()).f<number>(1, '');
>'' : ""

var r4b = (new C()).f<number, string, number>(1, '');
>r4b : any
>(new C()).f<number, string, number>(1, '') : any
>r4b : number
>(new C()).f<number, string, number>(1, '') : number
>(new C()).f : <T, U>(x: T, y: U) => T
>(new C()) : C
>new C() : C
Expand All @@ -106,17 +106,17 @@ var i: I;
>i : I

var r5 = i.f<number>(1, '');
>r5 : any
>i.f<number>(1, '') : any
>r5 : number
>i.f<number>(1, '') : number
>i.f : <T, U>(x: T, y: U) => T
>i : I
>f : <T, U>(x: T, y: U) => T
>1 : 1
>'' : ""

var r5b = i.f<number, string, number>(1, '');
>r5b : any
>i.f<number, string, number>(1, '') : any
>r5b : number
>i.f<number, string, number>(1, '') : number
>i.f : <T, U>(x: T, y: U) => T
>i : I
>f : <T, U>(x: T, y: U) => T
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/callOnInstance.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
tests/cases/compiler/callOnInstance.ts(1,18): error TS2300: Duplicate identifier 'D'.
tests/cases/compiler/callOnInstance.ts(3,15): error TS2300: Duplicate identifier 'D'.
tests/cases/compiler/callOnInstance.ts(7,19): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/callOnInstance.ts(7,19): error TS2554: Expected 0 arguments, but got 1.
tests/cases/compiler/callOnInstance.ts(10,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'C' has no compatible call signatures.


==== tests/cases/compiler/callOnInstance.ts (4 errors) ====
==== tests/cases/compiler/callOnInstance.ts (5 errors) ====
declare function D(): string; // error
~
!!! error TS2300: Duplicate identifier 'D'.
Expand All @@ -17,6 +18,8 @@ tests/cases/compiler/callOnInstance.ts(10,1): error TS2349: Cannot invoke an exp

var s2: string = (new D(1))();
~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
~~~~~~~~
!!! error TS2554: Expected 0 arguments, but got 1.

declare class C { constructor(value: number); }
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/callOverloads1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
tests/cases/compiler/callOverloads1.ts(1,7): error TS2300: Duplicate identifier 'Foo'.
tests/cases/compiler/callOverloads1.ts(9,10): error TS2300: Duplicate identifier 'Foo'.
tests/cases/compiler/callOverloads1.ts(9,10): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/compiler/callOverloads1.ts(13,10): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/callOverloads1.ts(13,10): error TS2554: Expected 0 arguments, but got 1.


==== tests/cases/compiler/callOverloads1.ts (4 errors) ====
==== tests/cases/compiler/callOverloads1.ts (5 errors) ====
class Foo { // error
~~~
!!! error TS2300: Duplicate identifier 'Foo'.
Expand All @@ -25,6 +26,8 @@ tests/cases/compiler/callOverloads1.ts(13,10): error TS2554: Expected 0 argument

var f1 = new Foo("hey");
~~~~~~~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
~~~~~~~~~~~~~~
!!! error TS2554: Expected 0 arguments, but got 1.


Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/callOverloads2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ tests/cases/compiler/callOverloads2.ts(11,10): error TS2389: Function implementa
tests/cases/compiler/callOverloads2.ts(11,10): error TS2393: Duplicate function implementation.
tests/cases/compiler/callOverloads2.ts(12,10): error TS2393: Duplicate function implementation.
tests/cases/compiler/callOverloads2.ts(14,10): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/compiler/callOverloads2.ts(18,10): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/callOverloads2.ts(18,10): error TS2554: Expected 0 arguments, but got 1.


==== tests/cases/compiler/callOverloads2.ts (7 errors) ====
==== tests/cases/compiler/callOverloads2.ts (8 errors) ====
class Foo { // error
~~~
!!! error TS2300: Duplicate identifier 'Foo'.
Expand Down Expand Up @@ -39,6 +40,8 @@ tests/cases/compiler/callOverloads2.ts(18,10): error TS2554: Expected 0 argument

var f1 = new Foo("hey");
~~~~~~~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
~~~~~~~~~~~~~~
!!! error TS2554: Expected 0 arguments, but got 1.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function foo() {
>"expects boolean instead of string" : "expects boolean instead of string"

test(true); // should error - string expected
>test(true) : any
>test(true) : void
>test : I1<string>
>true : true
}
8 changes: 4 additions & 4 deletions tests/baselines/reference/callWithMissingVoid.types
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ new MyPromise<void | number>(resolve => resolve()); // no error
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
>new MyPromise<any>(resolve => resolve()) : MyPromise<any>
>MyPromise : typeof MyPromise
>resolve => resolve() : (resolve: (value: any) => void) => any
>resolve => resolve() : (resolve: (value: any) => void) => void
>resolve : (value: any) => void
>resolve() : void
>resolve : (value: any) => void

new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
>new MyPromise<unknown>(resolve => resolve()) : MyPromise<unknown>
>MyPromise : typeof MyPromise
>resolve => resolve() : (resolve: (value: unknown) => void) => any
>resolve => resolve() : (resolve: (value: unknown) => void) => void
>resolve : (value: unknown) => void
>resolve() : void
>resolve : (value: unknown) => void

new MyPromise<never>(resolve => resolve()); // error, `never` arguments cannot be omitted
>new MyPromise<never>(resolve => resolve()) : MyPromise<never>
>MyPromise : typeof MyPromise
>resolve => resolve() : (resolve: (value: never) => void) => any
>resolve => resolve() : (resolve: (value: never) => void) => void
>resolve : (value: never) => void
>resolve() : void
>resolve : (value: never) => void
Expand Down Expand Up @@ -234,7 +234,7 @@ declare function call<TS extends unknown[]>(
>args : TS

call((x: number, y: number) => x + y) // error
>call((x: number, y: number) => x + y) : any
>call((x: number, y: number) => x + y) : void
>call : <TS extends unknown[]>(handler: (...args: TS) => unknown, ...args: TS) => void
>(x: number, y: number) => x + y : (x: number, y: number) => number
>x : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ function f<T, U>() { }
>f : <T, U>() => void

f<number>();
>f<number>() : any
>f<number>() : void
>f : <T, U>() => void

f<number, string>();
>f<number, string>() : void
>f : <T, U>() => void

f<number, string, number>();
>f<number, string, number>() : any
>f<number, string, number>() : void
>f : <T, U>() => void

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,64): error TS2741: Property 'z' is missing in type 'B' but required in type 'C'.
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,81): error TS2739: Type 'A' is missing the following properties from type 'C': z, y


==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (1 errors) ====
==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (2 errors) ====
class Chain<T extends A> {
constructor(public value: T) { }
then<S extends T>(cb: (x: T) => S): Chain<S> {
Expand All @@ -24,4 +25,7 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete
~~~~~
!!! error TS2741: Property 'z' is missing in type 'B' but required in type 'C'.
!!! related TS2728 tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts:15:5: 'z' is declared here.
!!! related TS6502 tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts:3:27: The expected type comes from the return type of this signature.
~~~~~
!!! error TS2739: Type 'A' is missing the following properties from type 'C': z, y
!!! related TS6502 tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts:3:27: The expected type comes from the return type of this signature.
Loading