Skip to content

Commit ed6cf5d

Browse files
Avoid over-expanding recursive constraints in getBaseSignature (#3769)
Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
1 parent 1fb728b commit ed6cf5d

6 files changed

Lines changed: 6 additions & 34 deletions

File tree

internal/checker/checker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19054,9 +19054,9 @@ func (c *Checker) getBaseSignature(signature *Signature) *Signature {
1905419054
baseConstraints := core.Map(typeParameters, func(tp *Type) *Type {
1905519055
return c.instantiateType(tp, baseConstraintMapper)
1905619056
})
19057-
// Run N type params thru the immediate constraint mapper up to N times
19058-
// This way any noncircular interdependent type parameters are definitely resolved to their external dependencies
19059-
for range typeParameters {
19057+
// Run the immediate constraint mapper N-1 times so non-circular interdependent type parameters
19058+
// resolve to their external dependencies without adding an extra expansion step for self-recursive constraints.
19059+
for range len(typeParameters) - 1 {
1906019060
baseConstraints = c.instantiateTypes(baseConstraints, baseConstraintMapper)
1906119061
}
1906219062
// and then apply a type eraser to remove any remaining circularly dependent type parameters

testdata/baselines/reference/submodule/conformance/genericFunctionParameters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare function f2<T>(cb: <S extends number>(x: S) => T): T;
2929
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
3030
declare let x1: unknown;
3131
declare let x2: number;
32-
declare let x3: any[][];
32+
declare let x3: any[];
3333
declare const s: <R>(go: <S>(ops: {
3434
init(): S;
3535
}) => R) => R;

testdata/baselines/reference/submodule/conformance/genericFunctionParameters.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ let x2 = f2(x => x); // number
3333
>x : S
3434

3535
let x3 = f3(x => x); // Array<any>
36-
>x3 : any[][]
37-
>f3(x => x) : any[][]
36+
>x3 : any[]
37+
>f3(x => x) : any[]
3838
>f3 : <T>(cb: <S extends Array<S>>(x: S) => T) => T
3939
>x => x : <S extends S[]>(x: S) => S
4040
>x : S

testdata/baselines/reference/submodule/conformance/genericFunctionParameters.types.diff

Lines changed: 0 additions & 13 deletions
This file was deleted.

testdata/baselines/reference/submoduleTriaged/conformance/genericFunctionParameters.js.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/submoduleTriaged.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ conformance/jsDeclarationsModuleReferenceHasEmit(target=es2015).js.diff
208208
## https://github.com/microsoft/typescript-go/issues/3563
209209
conformance/definiteAssignmentAssertionsWithObjectShortHand.js.diff
210210

211-
# Generic function parameter inference change
212-
## https://github.com/microsoft/typescript-go/issues/3564
213-
conformance/genericFunctionParameters.js.diff
214-
215211
# Late-bound computed property [prop] preserved instead of resolved to plain prop
216212
## https://github.com/microsoft/typescript-go/issues/3566
217213
compiler/lateBoundAssignmentCandidateJS2.js.diff

0 commit comments

Comments
 (0)