-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed regression in signature instantiation #59121
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
Merged
weswigham
merged 2 commits into
microsoft:main
from
Andarist:fix/sig-erasing-instantiation
Jul 9, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/genericCallInferenceConditionalType1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//// [tests/cases/compiler/genericCallInferenceConditionalType1.ts] //// | ||
|
||
=== genericCallInferenceConditionalType1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/59108 | ||
|
||
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown; | ||
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 13)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18)) | ||
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 21)) | ||
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 2, 25)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18)) | ||
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 2, 47)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18)) | ||
|
||
declare const g: <T extends unknown>(x: { foo: T }) => unknown; | ||
>g : Symbol(g, Decl(genericCallInferenceConditionalType1.ts, 3, 13)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 3, 18)) | ||
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 3, 37)) | ||
>foo : Symbol(foo, Decl(genericCallInferenceConditionalType1.ts, 3, 41)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 3, 18)) | ||
|
||
const h = f(g); | ||
>h : Symbol(h, Decl(genericCallInferenceConditionalType1.ts, 5, 5)) | ||
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 13)) | ||
>g : Symbol(g, Decl(genericCallInferenceConditionalType1.ts, 3, 13)) | ||
|
||
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown; | ||
>FirstParameter : Symbol(FirstParameter, Decl(genericCallInferenceConditionalType1.ts, 5, 15)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 7, 20)) | ||
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 7, 20)) | ||
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 7, 36)) | ||
>P : Symbol(P, Decl(genericCallInferenceConditionalType1.ts, 7, 44)) | ||
>P : Symbol(P, Decl(genericCallInferenceConditionalType1.ts, 7, 44)) | ||
|
||
type X = FirstParameter<typeof h>["foo"]; | ||
>X : Symbol(X, Decl(genericCallInferenceConditionalType1.ts, 7, 73)) | ||
>FirstParameter : Symbol(FirstParameter, Decl(genericCallInferenceConditionalType1.ts, 5, 15)) | ||
>h : Symbol(h, Decl(genericCallInferenceConditionalType1.ts, 5, 5)) | ||
|
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/genericCallInferenceConditionalType1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//// [tests/cases/compiler/genericCallInferenceConditionalType1.ts] //// | ||
|
||
=== genericCallInferenceConditionalType1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/59108 | ||
|
||
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown; | ||
>f : <T>(f: (x: T) => unknown) => (x: T) => unknown | ||
> : ^ ^^ ^^ ^^^^^ | ||
>f : (x: T) => unknown | ||
> : ^ ^^ ^^^^^ | ||
>x : T | ||
> : ^ | ||
>x : T | ||
> : ^ | ||
|
||
declare const g: <T extends unknown>(x: { foo: T }) => unknown; | ||
>g : <T extends unknown>(x: { foo: T; }) => unknown | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
>x : { foo: T; } | ||
> : ^^^^^^^ ^^^ | ||
>foo : T | ||
> : ^ | ||
|
||
const h = f(g); | ||
>h : <T extends unknown>(x: { foo: T; }) => unknown | ||
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^ | ||
>f(g) : <T extends unknown>(x: { foo: T; }) => unknown | ||
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^ | ||
>f : <T>(f: (x: T) => unknown) => (x: T) => unknown | ||
> : ^ ^^ ^^ ^^^^^ | ||
>g : <T extends unknown>(x: { foo: T; }) => unknown | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
|
||
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown; | ||
>FirstParameter : FirstParameter<T> | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>x : P | ||
> : ^ | ||
|
||
type X = FirstParameter<typeof h>["foo"]; | ||
>X : unknown | ||
> : ^^^^^^^ | ||
>h : <T extends unknown>(x: { foo: T; }) => unknown | ||
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^ | ||
|
13 changes: 13 additions & 0 deletions
13
tests/cases/compiler/genericCallInferenceConditionalType1.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/59108 | ||
|
||
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown; | ||
declare const g: <T extends unknown>(x: { foo: T }) => unknown; | ||
|
||
const h = f(g); | ||
|
||
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown; | ||
|
||
type X = FirstParameter<typeof h>["foo"]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the
signature
might already be a product ofinstantiateSignature
that was called withouteraseTypeParameters
and which thus cloned type parameters. Those cloned parameters are instantiated there in the arguments list using the availablemapper
but the same mapper wasn't later used when erasing type parameters from that result. This led to the mapper-instantiated cloned type parameter being left non-instantiated after erasing type parameters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% certain, but it may be better to do
sameMap
here just because that would avoid extra arrays when nothing actually needs to be mapped (but maybe it doesn't happen that often).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I pushed out a commit to use
sameMap
here