-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Do not erase signature constraints when calculating variance #55864
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
Draft
weswigham
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
weswigham:signature-variance-measurement-accuracy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec6f6ee
Add test demonstrating current bad behavior
weswigham bc9d806
Apply fix, explicitly annotate variance of array subtype in api, acce…
weswigham 7e3b8fc
Add out annotations to nonpublic array subtypes to let selfcheck pass
weswigham a0c09f1
Accept baseline
weswigham 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
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
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
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
74 changes: 74 additions & 0 deletions
74
...selines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(9,5): error TS2322: Type 'Fn<T2>' is not assignable to type 'Fn<T1>'. | ||
Type 'T1' is not assignable to type 'T2'. | ||
'T2' could be instantiated with an arbitrary type which could be unrelated to 'T1'. | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(10,5): error TS2322: Type 'Fn<T1>' is not assignable to type 'Fn<T2>'. | ||
Type 'T2' is not assignable to type 'T1'. | ||
'T1' could be instantiated with an arbitrary type which could be unrelated to 'T2'. | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(12,5): error TS2322: Type 'Concrete2' is not assignable to type 'Concrete1'. | ||
Types of parameters 'x' and 'x' are incompatible. | ||
Type 'U' is not assignable to type 'string'. | ||
Type 'number' is not assignable to type 'string'. | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(13,5): error TS2322: Type 'Concrete1' is not assignable to type 'Concrete2'. | ||
Types of parameters 'x' and 'x' are incompatible. | ||
Type 'U' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(15,5): error TS2322: Type 'Concrete1' is not assignable to type 'Fn<T1>'. | ||
Types of parameters 'x' and 'x' are incompatible. | ||
Type 'U' is not assignable to type 'number'. | ||
Type 'T1' is not assignable to type 'number'. | ||
genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(16,5): error TS2322: Type 'Fn<T1>' is not assignable to type 'Concrete1'. | ||
Types of parameters 'x' and 'x' are incompatible. | ||
Type 'U' is not assignable to type 'T1'. | ||
'T1' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
|
||
|
||
==== genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts (6 errors) ==== | ||
type Fn<T> = <U extends T>(x: U) => U; | ||
|
||
type Concrete1 = <U extends number>(x: U) => U; | ||
type Concrete2 = <U extends string>(x: U) => U; | ||
|
||
function f<T1, T2>(t1: Fn<T1>, t2: Fn<T2>, c1: Concrete1, c2: Concrete2) { | ||
// every single one of these assignments should error | ||
|
||
t1 = t2; | ||
~~ | ||
!!! error TS2322: Type 'Fn<T2>' is not assignable to type 'Fn<T1>'. | ||
!!! error TS2322: Type 'T1' is not assignable to type 'T2'. | ||
!!! error TS2322: 'T2' could be instantiated with an arbitrary type which could be unrelated to 'T1'. | ||
!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:12: This type parameter might need an `extends T2` constraint. | ||
t2 = t1; | ||
~~ | ||
!!! error TS2322: Type 'Fn<T1>' is not assignable to type 'Fn<T2>'. | ||
!!! error TS2322: Type 'T2' is not assignable to type 'T1'. | ||
!!! error TS2322: 'T1' could be instantiated with an arbitrary type which could be unrelated to 'T2'. | ||
!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:16: This type parameter might need an `extends T1` constraint. | ||
|
||
c1 = c2; | ||
~~ | ||
!!! error TS2322: Type 'Concrete2' is not assignable to type 'Concrete1'. | ||
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. | ||
!!! error TS2322: Type 'U' is not assignable to type 'string'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
c2 = c1; | ||
~~ | ||
!!! error TS2322: Type 'Concrete1' is not assignable to type 'Concrete2'. | ||
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. | ||
!!! error TS2322: Type 'U' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
||
t1 = c1; | ||
~~ | ||
!!! error TS2322: Type 'Concrete1' is not assignable to type 'Fn<T1>'. | ||
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. | ||
!!! error TS2322: Type 'U' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'T1' is not assignable to type 'number'. | ||
!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:12: This type parameter might need an `extends number` constraint. | ||
c1 = t1; | ||
~~ | ||
!!! error TS2322: Type 'Fn<T1>' is not assignable to type 'Concrete1'. | ||
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. | ||
!!! error TS2322: Type 'U' is not assignable to type 'T1'. | ||
!!! error TS2322: 'T1' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.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,33 @@ | ||
//// [tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] //// | ||
|
||
//// [genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] | ||
type Fn<T> = <U extends T>(x: U) => U; | ||
|
||
type Concrete1 = <U extends number>(x: U) => U; | ||
type Concrete2 = <U extends string>(x: U) => U; | ||
|
||
function f<T1, T2>(t1: Fn<T1>, t2: Fn<T2>, c1: Concrete1, c2: Concrete2) { | ||
// every single one of these assignments should error | ||
|
||
t1 = t2; | ||
t2 = t1; | ||
|
||
c1 = c2; | ||
c2 = c1; | ||
|
||
t1 = c1; | ||
c1 = t1; | ||
} | ||
|
||
|
||
//// [genericSignaturesConstrainedToDifferingGenericsNotCompatible.js] | ||
"use strict"; | ||
function f(t1, t2, c1, c2) { | ||
// every single one of these assignments should error | ||
t1 = t2; | ||
t2 = t1; | ||
c1 = c2; | ||
c2 = c1; | ||
t1 = c1; | ||
c1 = t1; | ||
} |
68 changes: 68 additions & 0 deletions
68
.../baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.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,68 @@ | ||
//// [tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] //// | ||
|
||
=== genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts === | ||
type Fn<T> = <U extends T>(x: U) => U; | ||
>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) | ||
>T : Symbol(T, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 8)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) | ||
>T : Symbol(T, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 8)) | ||
>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 27)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) | ||
|
||
type Concrete1 = <U extends number>(x: U) => U; | ||
>Concrete1 : Symbol(Concrete1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 38)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) | ||
>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 36)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) | ||
|
||
type Concrete2 = <U extends string>(x: U) => U; | ||
>Concrete2 : Symbol(Concrete2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 47)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) | ||
>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 36)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) | ||
>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) | ||
|
||
function f<T1, T2>(t1: Fn<T1>, t2: Fn<T2>, c1: Concrete1, c2: Concrete2) { | ||
>f : Symbol(f, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 47)) | ||
>T1 : Symbol(T1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 11)) | ||
>T2 : Symbol(T2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 14)) | ||
>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) | ||
>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) | ||
>T1 : Symbol(T1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 11)) | ||
>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) | ||
>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) | ||
>T2 : Symbol(T2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 14)) | ||
>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) | ||
>Concrete1 : Symbol(Concrete1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 38)) | ||
>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) | ||
>Concrete2 : Symbol(Concrete2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 47)) | ||
|
||
// every single one of these assignments should error | ||
|
||
t1 = t2; | ||
>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) | ||
>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) | ||
|
||
t2 = t1; | ||
>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) | ||
>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) | ||
|
||
c1 = c2; | ||
>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) | ||
>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) | ||
|
||
c2 = c1; | ||
>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) | ||
>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) | ||
|
||
t1 = c1; | ||
>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) | ||
>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) | ||
|
||
c1 = t1; | ||
>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) | ||
>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) | ||
} | ||
|
Oops, something went wrong.
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.
😵
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.
We go hard at finding the incompatibility, don't we. 😆
Guess there's an
any
somewhere in this type definition that should be anever
(or vice-versa, depending on intent).