Skip to content

Commit bbad560

Browse files
authored
Refrain from attempting to perform parameter fixing on a generic signature multiple times (#43835)
* Refrain from attempting to perform parameter fixing on a generic signature multiple times * Remove assertion
1 parent 353dc18 commit bbad560

5 files changed

+69
-1
lines changed

src/compiler/checker.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -30345,7 +30345,14 @@ namespace ts {
3034530345
}
3034630346

3034730347
function assignContextualParameterTypes(signature: Signature, context: Signature) {
30348-
signature.typeParameters = context.typeParameters;
30348+
if (context.typeParameters) {
30349+
if (!signature.typeParameters) {
30350+
signature.typeParameters = context.typeParameters;
30351+
}
30352+
else {
30353+
return; // This signature has already has a contextual inference performed and cached on it!
30354+
}
30355+
}
3034930356
if (context.thisParameter) {
3035030357
const parameter = signature.thisParameter;
3035130358
if (!parameter || parameter.valueDeclaration && !(<ParameterDeclaration>parameter.valueDeclaration).type) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [contextuallyTypedGenericAssignment.ts]
2+
function foo<A extends any[]>(
3+
arg: <T extends { a: number }>(t: T, ...rest: A) => number
4+
) { }
5+
6+
foo((t, u: number) => t.a)
7+
8+
//// [contextuallyTypedGenericAssignment.js]
9+
function foo(arg) { }
10+
foo(function (t, u) { return t.a; });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/contextuallyTypedGenericAssignment.ts ===
2+
function foo<A extends any[]>(
3+
>foo : Symbol(foo, Decl(contextuallyTypedGenericAssignment.ts, 0, 0))
4+
>A : Symbol(A, Decl(contextuallyTypedGenericAssignment.ts, 0, 13))
5+
6+
arg: <T extends { a: number }>(t: T, ...rest: A) => number
7+
>arg : Symbol(arg, Decl(contextuallyTypedGenericAssignment.ts, 0, 30))
8+
>T : Symbol(T, Decl(contextuallyTypedGenericAssignment.ts, 1, 10))
9+
>a : Symbol(a, Decl(contextuallyTypedGenericAssignment.ts, 1, 21))
10+
>t : Symbol(t, Decl(contextuallyTypedGenericAssignment.ts, 1, 35))
11+
>T : Symbol(T, Decl(contextuallyTypedGenericAssignment.ts, 1, 10))
12+
>rest : Symbol(rest, Decl(contextuallyTypedGenericAssignment.ts, 1, 40))
13+
>A : Symbol(A, Decl(contextuallyTypedGenericAssignment.ts, 0, 13))
14+
15+
) { }
16+
17+
foo((t, u: number) => t.a)
18+
>foo : Symbol(foo, Decl(contextuallyTypedGenericAssignment.ts, 0, 0))
19+
>t : Symbol(t, Decl(contextuallyTypedGenericAssignment.ts, 4, 5))
20+
>u : Symbol(u, Decl(contextuallyTypedGenericAssignment.ts, 4, 7))
21+
>t.a : Symbol(a, Decl(contextuallyTypedGenericAssignment.ts, 1, 21))
22+
>t : Symbol(t, Decl(contextuallyTypedGenericAssignment.ts, 4, 5))
23+
>a : Symbol(a, Decl(contextuallyTypedGenericAssignment.ts, 1, 21))
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/contextuallyTypedGenericAssignment.ts ===
2+
function foo<A extends any[]>(
3+
>foo : <A extends any[]>(arg: <T extends { a: number; }>(t: T, ...rest: A) => number) => void
4+
5+
arg: <T extends { a: number }>(t: T, ...rest: A) => number
6+
>arg : <T extends { a: number; }>(t: T, ...rest: A) => number
7+
>a : number
8+
>t : T
9+
>rest : A
10+
11+
) { }
12+
13+
foo((t, u: number) => t.a)
14+
>foo((t, u: number) => t.a) : void
15+
>foo : <A extends any[]>(arg: <T extends { a: number; }>(t: T, ...rest: A) => number) => void
16+
>(t, u: number) => t.a : <T extends { a: number; }>(t: T, u: number) => number
17+
>t : T
18+
>u : number
19+
>t.a : number
20+
>t : T
21+
>a : number
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function foo<A extends any[]>(
2+
arg: <T extends { a: number }>(t: T, ...rest: A) => number
3+
) { }
4+
5+
foo((t, u: number) => t.a)

0 commit comments

Comments
 (0)