Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36385,7 +36385,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (result) {
return result;
}
result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
checkNodeDeferred(node);
result = candidates.length === 1 && candidatesForArgumentError?.length === 1 ? candidatesForArgumentError[0] : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
// Preemptively cache the result; getResolvedSignature will do this after we return, but
// we need to ensure that the result is present for the error checks below so that if
// this signature is encountered again, we handle the circularity (rather than producing a
Expand Down Expand Up @@ -36621,7 +36622,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkMode: CheckMode,
): Signature {
Debug.assert(candidates.length > 0); // Else should not have called this.
checkNodeDeferred(node);
// Normally we will combine overloads. Skip this if they have type parameters since that's hard to combine.
// Don't do this if there is a `candidatesOutArray`,
// because then we want the chosen best candidate to be one of the overloads, not a combination.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
contextualSignatureInstantiation.ts(19,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
contextualSignatureInstantiation.ts(19,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'number'.
contextualSignatureInstantiation.ts(19,13): error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: number, y: string) => number'.
Types of parameters 'y' and 'y' are incompatible.
Type 'string' is not assignable to type 'number'.
contextualSignatureInstantiation.ts(20,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
contextualSignatureInstantiation.ts(20,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'number'.
contextualSignatureInstantiation.ts(20,23): error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: number, y: string) => number'.
Types of parameters 'y' and 'y' are incompatible.
Type 'string' is not assignable to type 'number'.
contextualSignatureInstantiation.ts(21,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
contextualSignatureInstantiation.ts(21,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'string'.
contextualSignatureInstantiation.ts(21,23): error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: string, y: number) => string'.
Types of parameters 'y' and 'y' are incompatible.
Type 'number' is not assignable to type 'string'.
Expand All @@ -33,29 +33,31 @@ contextualSignatureInstantiation.ts(21,23): error TS2345: Argument of type '<T>(
var b: number | string;
var b = foo(g); // Error, number and string are disjoint types
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'number'.
!!! related TS6203 contextualSignatureInstantiation.ts:18:5: 'b' was also declared here.
~
!!! error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: number, y: string) => number'.
!!! error TS2345: Types of parameters 'y' and 'y' are incompatible.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
var b = bar(1, "one", g); // Error, number and string are disjoint types
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'number'.
!!! related TS6203 contextualSignatureInstantiation.ts:18:5: 'b' was also declared here.
~
!!! error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: number, y: string) => number'.
!!! error TS2345: Types of parameters 'y' and 'y' are incompatible.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
var b = bar("one", 1, g); // Error, number and string are disjoint types
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'unknown'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'string | number', but here has type 'string'.
!!! related TS6203 contextualSignatureInstantiation.ts:18:5: 'b' was also declared here.
~
!!! error TS2345: Argument of type '<T>(x: T, y: T) => T' is not assignable to parameter of type '(x: string, y: number) => string'.
!!! error TS2345: Types of parameters 'y' and 'y' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
var b = baz(b, b, g); // Should be number | string

var b2: number | string;
var b2 = baz(b2, b2, g); // Should be number | string

var d: number[] | string[];
var d = foo(h); // Should be number[] | string[]
Expand Down
7 changes: 5 additions & 2 deletions tests/baselines/reference/contextualSignatureInstantiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var b: number | string;
var b = foo(g); // Error, number and string are disjoint types
var b = bar(1, "one", g); // Error, number and string are disjoint types
var b = bar("one", 1, g); // Error, number and string are disjoint types
var b = baz(b, b, g); // Should be number | string

var b2: number | string;
var b2 = baz(b2, b2, g); // Should be number | string

var d: number[] | string[];
var d = foo(h); // Should be number[] | string[]
Expand All @@ -44,7 +46,8 @@ var b;
var b = foo(g); // Error, number and string are disjoint types
var b = bar(1, "one", g); // Error, number and string are disjoint types
var b = bar("one", 1, g); // Error, number and string are disjoint types
var b = baz(b, b, g); // Should be number | string
var b2;
var b2 = baz(b2, b2, g); // Should be number | string
var d;
var d = foo(h); // Should be number[] | string[]
var d = bar(1, "one", h); // Should be number[] | string[]
Expand Down
33 changes: 18 additions & 15 deletions tests/baselines/reference/contextualSignatureInstantiation.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -83,52 +83,55 @@ var a = baz(1, 1, g); // Should be number
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

var b: number | string;
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3))

var b = foo(g); // Error, number and string are disjoint types
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3))
>foo : Symbol(foo, Decl(contextualSignatureInstantiation.ts, 0, 0))
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

var b = bar(1, "one", g); // Error, number and string are disjoint types
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3))
>bar : Symbol(bar, Decl(contextualSignatureInstantiation.ts, 6, 60))
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

var b = bar("one", 1, g); // Error, number and string are disjoint types
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3))
>bar : Symbol(bar, Decl(contextualSignatureInstantiation.ts, 6, 60))
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

var b = baz(b, b, g); // Should be number | string
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
var b2: number | string;
>b2 : Symbol(b2, Decl(contextualSignatureInstantiation.ts, 22, 3), Decl(contextualSignatureInstantiation.ts, 23, 3))

var b2 = baz(b2, b2, g); // Should be number | string
>b2 : Symbol(b2, Decl(contextualSignatureInstantiation.ts, 22, 3), Decl(contextualSignatureInstantiation.ts, 23, 3))
>baz : Symbol(baz, Decl(contextualSignatureInstantiation.ts, 7, 68))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b : Symbol(b, Decl(contextualSignatureInstantiation.ts, 17, 3), Decl(contextualSignatureInstantiation.ts, 18, 3), Decl(contextualSignatureInstantiation.ts, 19, 3), Decl(contextualSignatureInstantiation.ts, 20, 3), Decl(contextualSignatureInstantiation.ts, 21, 3))
>b2 : Symbol(b2, Decl(contextualSignatureInstantiation.ts, 22, 3), Decl(contextualSignatureInstantiation.ts, 23, 3))
>b2 : Symbol(b2, Decl(contextualSignatureInstantiation.ts, 22, 3), Decl(contextualSignatureInstantiation.ts, 23, 3))
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

var d: number[] | string[];
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))

var d = foo(h); // Should be number[] | string[]
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>foo : Symbol(foo, Decl(contextualSignatureInstantiation.ts, 0, 0))
>h : Symbol(h, Decl(contextualSignatureInstantiation.ts, 10, 37))

var d = bar(1, "one", h); // Should be number[] | string[]
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>bar : Symbol(bar, Decl(contextualSignatureInstantiation.ts, 6, 60))
>h : Symbol(h, Decl(contextualSignatureInstantiation.ts, 10, 37))

var d = bar("one", 1, h); // Should be number[] | string[]
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>bar : Symbol(bar, Decl(contextualSignatureInstantiation.ts, 6, 60))
>h : Symbol(h, Decl(contextualSignatureInstantiation.ts, 10, 37))

var d = baz(d, d, g); // Should be number[] | string[]
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>baz : Symbol(baz, Decl(contextualSignatureInstantiation.ts, 7, 68))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 23, 3), Decl(contextualSignatureInstantiation.ts, 24, 3), Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>d : Symbol(d, Decl(contextualSignatureInstantiation.ts, 25, 3), Decl(contextualSignatureInstantiation.ts, 26, 3), Decl(contextualSignatureInstantiation.ts, 27, 3), Decl(contextualSignatureInstantiation.ts, 28, 3), Decl(contextualSignatureInstantiation.ts, 29, 3))
>g : Symbol(g, Decl(contextualSignatureInstantiation.ts, 8, 65))

34 changes: 19 additions & 15 deletions tests/baselines/reference/contextualSignatureInstantiation.types
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ var b: number | string;
var b = foo(g); // Error, number and string are disjoint types
>b : string | number
> : ^^^^^^^^^^^^^^^
>foo(g) : unknown
> : ^^^^^^^
>foo(g) : number
> : ^^^^^^
>foo : <T>(cb: (x: number, y: string) => T) => T
> : ^ ^^ ^^ ^^^^^
>g : <T>(x: T, y: T) => T
Expand All @@ -110,8 +110,8 @@ var b = foo(g); // Error, number and string are disjoint types
var b = bar(1, "one", g); // Error, number and string are disjoint types
>b : string | number
> : ^^^^^^^^^^^^^^^
>bar(1, "one", g) : unknown
> : ^^^^^^^
>bar(1, "one", g) : number
> : ^^^^^^
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>1 : 1
Expand All @@ -124,8 +124,8 @@ var b = bar(1, "one", g); // Error, number and string are disjoint types
var b = bar("one", 1, g); // Error, number and string are disjoint types
>b : string | number
> : ^^^^^^^^^^^^^^^
>bar("one", 1, g) : unknown
> : ^^^^^^^
>bar("one", 1, g) : string
> : ^^^^^^
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>"one" : "one"
Expand All @@ -135,17 +135,21 @@ var b = bar("one", 1, g); // Error, number and string are disjoint types
>g : <T>(x: T, y: T) => T
> : ^ ^^ ^^ ^^ ^^ ^^^^^

var b = baz(b, b, g); // Should be number | string
>b : string | number
> : ^^^^^^^^^^^^^^^
>baz(b, b, g) : string | number
> : ^^^^^^^^^^^^^^^
var b2: number | string;
>b2 : string | number
> : ^^^^^^^^^^^^^^^

var b2 = baz(b2, b2, g); // Should be number | string
>b2 : string | number
> : ^^^^^^^^^^^^^^^
>baz(b2, b2, g) : string | number
> : ^^^^^^^^^^^^^^^
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>b : string | number
> : ^^^^^^^^^^^^^^^
>b : string | number
> : ^^^^^^^^^^^^^^^
>b2 : string | number
> : ^^^^^^^^^^^^^^^
>b2 : string | number
> : ^^^^^^^^^^^^^^^
>g : <T>(x: T, y: T) => T
> : ^ ^^ ^^ ^^ ^^ ^^^^^

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/generatorTypeCheck62.types
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export const Nothing2: Strategy<State> = strategy("Nothing", function*(state: St
export const Nothing3: Strategy<State> = strategy("Nothing", function* (state: State) {
>Nothing3 : Strategy<State>
> : ^^^^^^^^^^^^^^^
>strategy("Nothing", function* (state: State) { yield ; return state; // `return`/`TReturn` isn't supported by `strategy`, so this should error.}) : (a: State) => IterableIterator<State, void>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>strategy("Nothing", function* (state: State) { yield ; return state; // `return`/`TReturn` isn't supported by `strategy`, so this should error.}) : (a: any) => IterableIterator<any, void>
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>strategy : <T extends StrategicState>(stratName: string, gen: (a: T) => IterableIterator<T | undefined, void>) => (a: T) => IterableIterator<T | undefined, void>
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^
>"Nothing" : "Nothing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ var r = foo(arg); // {}

// more args not allowed
var r2 = foo({ cb: <T>(x: T, y: T) => '' }); // error
>r2 : unknown
> : ^^^^^^^
>foo({ cb: <T>(x: T, y: T) => '' }) : unknown
> : ^^^^^^^
>r2 : string
> : ^^^^^^
>foo({ cb: <T>(x: T, y: T) => '' }) : string
> : ^^^^^^
>foo : <T, U>(arg: { cb: (t: T) => U; }) => U
> : ^ ^^ ^^ ^^ ^^^^^^
>{ cb: <T>(x: T, y: T) => '' } : { cb: <T>(x: T, y: T) => string; }
Expand Down
Loading
Loading