-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Widen inference candidates for error reporting #15221
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7bc10c7
Widen inference candidates for error reporting
sandersn 862fa45
Test widening inference candidates for err reports
sandersn 8486b61
Policheck made-up Romance words and improve types
sandersn 3541c38
getCommonSupertype correctly widens unions
sandersn 8067395
Update test comments
sandersn 502803a
Update test too.
sandersn f56fe9e
Improve new assert in reportNoCommonSupertypeError
sandersn b0c38e8
Merge branch 'master' into widen-inference-candidates-for-error-repor…
sandersn db3d88e
getNullableType supports void
sandersn 637581b
Fix semicolon lint
sandersn ec9e280
Restore getNullableType and getCommonSupertype
sandersn bf4961b
Fix indentation
sandersn 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
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. | ||
Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. | ||
Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. | ||
|
||
|
||
==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ==== | ||
function bar<T>(item1: T, item2: T) { } | ||
bar(1, ""); // Should be ok | ||
~~~ | ||
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. | ||
!!! error TS2453: Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. | ||
!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '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
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js
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,14 @@ | ||
//// [noCommonSupertypeTypeInferenceMatchesReporting.ts] | ||
// Fixes #15116, which asserted on line 5 but not 6 | ||
declare function f<T>(a: T, b: T): boolean; | ||
function g(gut: { n: 12 | undefined }) { | ||
f(gut.n, 12); // ok, T = number | undefined | ||
f(12, gut.n); // ok, T = number | undefined | ||
} | ||
|
||
|
||
//// [noCommonSupertypeTypeInferenceMatchesReporting.js] | ||
function g(gut) { | ||
f(gut.n, 12); // ok, T = number | undefined | ||
f(12, gut.n); // ok, T = number | undefined | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.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,28 @@ | ||
=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === | ||
// Fixes #15116, which asserted on line 5 but not 6 | ||
declare function f<T>(a: T, b: T): boolean; | ||
>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) | ||
>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) | ||
>a : Symbol(a, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 22)) | ||
>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) | ||
>b : Symbol(b, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 27)) | ||
>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) | ||
|
||
function g(gut: { n: 12 | undefined }) { | ||
>g : Symbol(g, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 43)) | ||
>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) | ||
>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) | ||
|
||
f(gut.n, 12); // ok, T = number | undefined | ||
>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) | ||
>gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) | ||
>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) | ||
>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) | ||
|
||
f(12, gut.n); // ok, T = number | undefined | ||
>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) | ||
>gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) | ||
>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) | ||
>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.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,32 @@ | ||
=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === | ||
// Fixes #15116, which asserted on line 5 but not 6 | ||
declare function f<T>(a: T, b: T): boolean; | ||
>f : <T>(a: T, b: T) => boolean | ||
>T : T | ||
>a : T | ||
>T : T | ||
>b : T | ||
>T : T | ||
|
||
function g(gut: { n: 12 | undefined }) { | ||
>g : (gut: { n: 12 | undefined; }) => void | ||
>gut : { n: 12 | undefined; } | ||
>n : 12 | undefined | ||
|
||
f(gut.n, 12); // ok, T = number | undefined | ||
>f(gut.n, 12) : boolean | ||
>f : <T>(a: T, b: T) => boolean | ||
>gut.n : 12 | undefined | ||
>gut : { n: 12 | undefined; } | ||
>n : 12 | undefined | ||
>12 : 12 | ||
|
||
f(12, gut.n); // ok, T = number | undefined | ||
>f(12, gut.n) : boolean | ||
>f : <T>(a: T, b: T) => boolean | ||
>12 : 12 | ||
>gut.n : 12 | undefined | ||
>gut : { n: 12 | undefined; } | ||
>n : 12 | undefined | ||
} | ||
|
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
7 changes: 7 additions & 0 deletions
7
tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.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,7 @@ | ||
// @strictNullChecks: true | ||
// Fixes #15116, which asserted on line 5 but not 6 | ||
declare function f<T>(a: T, b: T): boolean; | ||
function g(gut: { n: 12 | undefined }) { | ||
f(gut.n, 12); // ok, T = number | undefined | ||
f(12, gut.n); // ok, T = number | undefined | ||
} |
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 code moves into
getInferenceCandidates
so that both type inference (this section) and type inference error reporting (the other call togetInferenceCandidates
) widen the same way.