-
Notifications
You must be signed in to change notification settings - Fork 1k
Prefer covariant inferences with deeper type argument nesting #4389
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
Merged
Changes from all commits
Commits
Show all changes
5 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
90 changes: 90 additions & 0 deletions
90
testdata/baselines/reference/compiler/nestedGenericTypeInference.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,90 @@ | ||
| //// [tests/cases/compiler/nestedGenericTypeInference.ts] //// | ||
|
|
||
| === nestedGenericTypeInference.ts === | ||
| // https://github.com/microsoft/typescript-go/issues/1789 | ||
|
|
||
| declare function flat<T>(args: T[] | T[][]): void; | ||
| >flat : Symbol(flat, Decl(nestedGenericTypeInference.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 2, 22)) | ||
| >args : Symbol(args, Decl(nestedGenericTypeInference.ts, 2, 25)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 2, 22)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 2, 22)) | ||
|
|
||
| type Value = 1 | 2; | ||
| >Value : Symbol(Value, Decl(nestedGenericTypeInference.ts, 2, 50)) | ||
|
|
||
| declare const n: Value[] | Value[][]; | ||
| >n : Symbol(n, Decl(nestedGenericTypeInference.ts, 4, 13)) | ||
| >Value : Symbol(Value, Decl(nestedGenericTypeInference.ts, 2, 50)) | ||
| >Value : Symbol(Value, Decl(nestedGenericTypeInference.ts, 2, 50)) | ||
|
|
||
| flat(n); | ||
| >flat : Symbol(flat, Decl(nestedGenericTypeInference.ts, 0, 0)) | ||
| >n : Symbol(n, Decl(nestedGenericTypeInference.ts, 4, 13)) | ||
|
|
||
| type Box<T> = { value: T }; | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 7, 9)) | ||
| >value : Symbol(value, Decl(nestedGenericTypeInference.ts, 7, 15)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 7, 9)) | ||
|
|
||
| declare function flat0<T>(args: Box<T> | Box<Box<T>>): void; | ||
| >flat0 : Symbol(flat0, Decl(nestedGenericTypeInference.ts, 7, 27)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 9, 23)) | ||
| >args : Symbol(args, Decl(nestedGenericTypeInference.ts, 9, 26)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 9, 23)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 9, 23)) | ||
|
|
||
| declare const arg0: Box<string> | Box<Box<string>>; | ||
| >arg0 : Symbol(arg0, Decl(nestedGenericTypeInference.ts, 10, 13)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
|
|
||
| flat0(arg0); | ||
| >flat0 : Symbol(flat0, Decl(nestedGenericTypeInference.ts, 7, 27)) | ||
| >arg0 : Symbol(arg0, Decl(nestedGenericTypeInference.ts, 10, 13)) | ||
|
|
||
| declare function flat1<T>(args: Array<T> | Array<Box<T>>): void; | ||
| >flat1 : Symbol(flat1, Decl(nestedGenericTypeInference.ts, 11, 12)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 13, 23)) | ||
| >args : Symbol(args, Decl(nestedGenericTypeInference.ts, 13, 26)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 13, 23)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 13, 23)) | ||
|
|
||
| declare const arg1: Array<string> | Array<Box<string>>; | ||
| >arg1 : Symbol(arg1, Decl(nestedGenericTypeInference.ts, 14, 13)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
|
|
||
| flat1(arg1); | ||
| >flat1 : Symbol(flat1, Decl(nestedGenericTypeInference.ts, 11, 12)) | ||
| >arg1 : Symbol(arg1, Decl(nestedGenericTypeInference.ts, 14, 13)) | ||
|
|
||
| declare function flat2<T>(args: Box<T> | Box<Array<T>>): void; | ||
| >flat2 : Symbol(flat2, Decl(nestedGenericTypeInference.ts, 15, 12)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 17, 23)) | ||
| >args : Symbol(args, Decl(nestedGenericTypeInference.ts, 17, 26)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 17, 23)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
| >T : Symbol(T, Decl(nestedGenericTypeInference.ts, 17, 23)) | ||
|
|
||
| declare const arg2: Box<string> | Box<Array<string>>; | ||
| >arg2 : Symbol(arg2, Decl(nestedGenericTypeInference.ts, 18, 13)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Box : Symbol(Box, Decl(nestedGenericTypeInference.ts, 5, 8)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
|
|
||
| flat2(arg2); | ||
| >flat2 : Symbol(flat2, Decl(nestedGenericTypeInference.ts, 15, 12)) | ||
| >arg2 : Symbol(arg2, Decl(nestedGenericTypeInference.ts, 18, 13)) | ||
|
|
60 changes: 60 additions & 0 deletions
60
testdata/baselines/reference/compiler/nestedGenericTypeInference.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,60 @@ | ||
| //// [tests/cases/compiler/nestedGenericTypeInference.ts] //// | ||
|
|
||
| === nestedGenericTypeInference.ts === | ||
| // https://github.com/microsoft/typescript-go/issues/1789 | ||
|
|
||
| declare function flat<T>(args: T[] | T[][]): void; | ||
| >flat : <T>(args: T[] | T[][]) => void | ||
| >args : T[] | T[][] | ||
|
|
||
| type Value = 1 | 2; | ||
| >Value : Value | ||
|
|
||
| declare const n: Value[] | Value[][]; | ||
| >n : Value[][] | Value[] | ||
|
|
||
| flat(n); | ||
| >flat(n) : void | ||
| >flat : <T>(args: T[] | T[][]) => void | ||
| >n : Value[][] | Value[] | ||
|
|
||
| type Box<T> = { value: T }; | ||
| >Box : Box<T> | ||
| >value : T | ||
|
|
||
| declare function flat0<T>(args: Box<T> | Box<Box<T>>): void; | ||
| >flat0 : <T>(args: Box<T> | Box<Box<T>>) => void | ||
| >args : Box<T> | Box<Box<T>> | ||
|
|
||
| declare const arg0: Box<string> | Box<Box<string>>; | ||
| >arg0 : Box<string> | Box<Box<string>> | ||
|
|
||
| flat0(arg0); | ||
| >flat0(arg0) : void | ||
| >flat0 : <T>(args: Box<T> | Box<Box<T>>) => void | ||
| >arg0 : Box<string> | Box<Box<string>> | ||
|
|
||
| declare function flat1<T>(args: Array<T> | Array<Box<T>>): void; | ||
| >flat1 : <T>(args: Array<T> | Array<Box<T>>) => void | ||
| >args : T[] | Box<T>[] | ||
|
|
||
| declare const arg1: Array<string> | Array<Box<string>>; | ||
| >arg1 : string[] | Box<string>[] | ||
|
|
||
| flat1(arg1); | ||
| >flat1(arg1) : void | ||
| >flat1 : <T>(args: Array<T> | Array<Box<T>>) => void | ||
| >arg1 : string[] | Box<string>[] | ||
|
|
||
| declare function flat2<T>(args: Box<T> | Box<Array<T>>): void; | ||
| >flat2 : <T>(args: Box<T> | Box<Array<T>>) => void | ||
| >args : Box<T> | Box<T[]> | ||
|
|
||
| declare const arg2: Box<string> | Box<Array<string>>; | ||
| >arg2 : Box<string> | Box<string[]> | ||
|
|
||
| flat2(arg2); | ||
| >flat2(arg2) : void | ||
| >flat2 : <T>(args: Box<T> | Box<Array<T>>) => void | ||
| >arg2 : Box<string> | Box<string[]> | ||
|
|
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
25 changes: 25 additions & 0 deletions
25
...eference/submodule/conformance/assignmentCompatWithGenericCallSignatures2.errors.txt.diff
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,25 @@ | ||
| --- old.assignmentCompatWithGenericCallSignatures2.errors.txt | ||
| +++ new.assignmentCompatWithGenericCallSignatures2.errors.txt | ||
| @@= skipped -0, +0 lines =@@ | ||
| assignmentCompatWithGenericCallSignatures2.ts(15,1): error TS2322: Type 'B' is not assignable to type 'A'. | ||
| - Types of parameters 'y' and 'y' are incompatible. | ||
| - Type 'T[]' is not assignable to type 'T'. | ||
| - 'T' could be instantiated with an arbitrary type which could be unrelated to 'T[]'. | ||
| + Types of parameters 'x' and 'x' are incompatible. | ||
| + Type 'T' is not assignable to type 'T[]'. | ||
| assignmentCompatWithGenericCallSignatures2.ts(16,1): error TS2322: Type 'A' is not assignable to type 'B'. | ||
| Types of parameters 'y' and 'y' are incompatible. | ||
| Type 'S' is not assignable to type 'S[]'. | ||
| @@= skipped -24, +23 lines =@@ | ||
| a = b; | ||
| ~ | ||
| !!! error TS2322: Type 'B' is not assignable to type 'A'. | ||
| -!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. | ||
| -!!! error TS2322: Type 'T[]' is not assignable to type 'T'. | ||
| -!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T[]'. | ||
| +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. | ||
| +!!! error TS2322: Type 'T' is not assignable to type 'T[]'. | ||
| +!!! related TS2208 assignmentCompatWithGenericCallSignatures2.ts:4:6: This type parameter might need an `extends T[]` constraint. | ||
| b = a; | ||
| ~ | ||
| !!! error TS2322: Type 'A' is not assignable to type 'B'. | ||
22 changes: 22 additions & 0 deletions
22
testdata/tests/cases/compiler/nestedGenericTypeInference.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,22 @@ | ||
| // @noEmit: true | ||
|
|
||
| // https://github.com/microsoft/typescript-go/issues/1789 | ||
|
|
||
| declare function flat<T>(args: T[] | T[][]): void; | ||
| type Value = 1 | 2; | ||
| declare const n: Value[] | Value[][]; | ||
| flat(n); | ||
|
|
||
| type Box<T> = { value: T }; | ||
|
|
||
| declare function flat0<T>(args: Box<T> | Box<Box<T>>): void; | ||
| declare const arg0: Box<string> | Box<Box<string>>; | ||
| flat0(arg0); | ||
|
|
||
| declare function flat1<T>(args: Array<T> | Array<Box<T>>): void; | ||
| declare const arg1: Array<string> | Array<Box<string>>; | ||
| flat1(arg1); | ||
|
|
||
| declare function flat2<T>(args: Box<T> | Box<Array<T>>): void; | ||
| declare const arg2: Box<string> | Box<Array<string>>; | ||
| flat2(arg2); |
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.
This is intended.