-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add test which would fail if SFT behavior differs in variance checking #54756
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 1 commit into
microsoft:main
from
weswigham:add-test-while-fails-if-variance-sfc-behavior-differs
Jun 23, 2023
Merged
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/varianceCantBeStrictWhileStructureIsnt.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,39 @@ | ||
//// [tests/cases/compiler/varianceCantBeStrictWhileStructureIsnt.ts] //// | ||
|
||
//// [varianceCantBeStrictWhileStructureIsnt.ts] | ||
// under non-strict-function-types, all the below should work | ||
interface Foo<T> { | ||
member: (cb: T) => void; | ||
} | ||
|
||
interface Bar<T> { | ||
member: (cb: T) => void; | ||
} | ||
|
||
declare var a: Foo<string>; | ||
declare var b: Foo<"">; | ||
|
||
declare var a2: Bar<string>; | ||
declare var b2: Bar<"">; | ||
|
||
a = b; | ||
b = a; | ||
|
||
a2 = b2; | ||
b2 = a2; | ||
|
||
a = b2; | ||
b = a2; | ||
|
||
a2 = b; | ||
b2 = a; | ||
|
||
//// [varianceCantBeStrictWhileStructureIsnt.js] | ||
a = b; | ||
b = a; | ||
a2 = b2; | ||
b2 = a2; | ||
a = b2; | ||
b = a2; | ||
a2 = b; | ||
b2 = a; |
72 changes: 72 additions & 0 deletions
72
tests/baselines/reference/varianceCantBeStrictWhileStructureIsnt.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,72 @@ | ||
//// [tests/cases/compiler/varianceCantBeStrictWhileStructureIsnt.ts] //// | ||
|
||
=== varianceCantBeStrictWhileStructureIsnt.ts === | ||
// under non-strict-function-types, all the below should work | ||
interface Foo<T> { | ||
>Foo : Symbol(Foo, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 0, 0)) | ||
>T : Symbol(T, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 1, 14)) | ||
|
||
member: (cb: T) => void; | ||
>member : Symbol(Foo.member, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 1, 18)) | ||
>cb : Symbol(cb, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 2, 13)) | ||
>T : Symbol(T, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 1, 14)) | ||
} | ||
|
||
interface Bar<T> { | ||
>Bar : Symbol(Bar, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 3, 1)) | ||
>T : Symbol(T, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 5, 14)) | ||
|
||
member: (cb: T) => void; | ||
>member : Symbol(Bar.member, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 5, 18)) | ||
>cb : Symbol(cb, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 6, 13)) | ||
>T : Symbol(T, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 5, 14)) | ||
} | ||
|
||
declare var a: Foo<string>; | ||
>a : Symbol(a, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 9, 11)) | ||
>Foo : Symbol(Foo, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 0, 0)) | ||
|
||
declare var b: Foo<"">; | ||
>b : Symbol(b, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 10, 11)) | ||
>Foo : Symbol(Foo, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 0, 0)) | ||
|
||
declare var a2: Bar<string>; | ||
>a2 : Symbol(a2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 12, 11)) | ||
>Bar : Symbol(Bar, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 3, 1)) | ||
|
||
declare var b2: Bar<"">; | ||
>b2 : Symbol(b2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 13, 11)) | ||
>Bar : Symbol(Bar, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 3, 1)) | ||
|
||
a = b; | ||
>a : Symbol(a, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 9, 11)) | ||
>b : Symbol(b, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 10, 11)) | ||
|
||
b = a; | ||
>b : Symbol(b, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 10, 11)) | ||
>a : Symbol(a, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 9, 11)) | ||
|
||
a2 = b2; | ||
>a2 : Symbol(a2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 12, 11)) | ||
>b2 : Symbol(b2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 13, 11)) | ||
|
||
b2 = a2; | ||
>b2 : Symbol(b2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 13, 11)) | ||
>a2 : Symbol(a2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 12, 11)) | ||
|
||
a = b2; | ||
>a : Symbol(a, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 9, 11)) | ||
>b2 : Symbol(b2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 13, 11)) | ||
|
||
b = a2; | ||
>b : Symbol(b, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 10, 11)) | ||
>a2 : Symbol(a2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 12, 11)) | ||
|
||
a2 = b; | ||
>a2 : Symbol(a2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 12, 11)) | ||
>b : Symbol(b, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 10, 11)) | ||
|
||
b2 = a; | ||
>b2 : Symbol(b2, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 13, 11)) | ||
>a : Symbol(a, Decl(varianceCantBeStrictWhileStructureIsnt.ts, 9, 11)) | ||
|
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/varianceCantBeStrictWhileStructureIsnt.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,68 @@ | ||
//// [tests/cases/compiler/varianceCantBeStrictWhileStructureIsnt.ts] //// | ||
|
||
=== varianceCantBeStrictWhileStructureIsnt.ts === | ||
// under non-strict-function-types, all the below should work | ||
interface Foo<T> { | ||
member: (cb: T) => void; | ||
>member : (cb: T) => void | ||
>cb : T | ||
} | ||
|
||
interface Bar<T> { | ||
member: (cb: T) => void; | ||
>member : (cb: T) => void | ||
>cb : T | ||
} | ||
|
||
declare var a: Foo<string>; | ||
>a : Foo<string> | ||
|
||
declare var b: Foo<"">; | ||
>b : Foo<""> | ||
|
||
declare var a2: Bar<string>; | ||
>a2 : Bar<string> | ||
|
||
declare var b2: Bar<"">; | ||
>b2 : Bar<""> | ||
|
||
a = b; | ||
>a = b : Foo<""> | ||
>a : Foo<string> | ||
>b : Foo<""> | ||
|
||
b = a; | ||
>b = a : Foo<string> | ||
>b : Foo<""> | ||
>a : Foo<string> | ||
|
||
a2 = b2; | ||
>a2 = b2 : Bar<""> | ||
>a2 : Bar<string> | ||
>b2 : Bar<""> | ||
|
||
b2 = a2; | ||
>b2 = a2 : Bar<string> | ||
>b2 : Bar<""> | ||
>a2 : Bar<string> | ||
|
||
a = b2; | ||
>a = b2 : Bar<""> | ||
>a : Foo<string> | ||
>b2 : Bar<""> | ||
|
||
b = a2; | ||
>b = a2 : Bar<string> | ||
>b : Foo<""> | ||
>a2 : Bar<string> | ||
|
||
a2 = b; | ||
>a2 = b : Foo<""> | ||
>a2 : Bar<string> | ||
>b : Foo<""> | ||
|
||
b2 = a; | ||
>b2 = a : Foo<string> | ||
>b2 : Bar<""> | ||
>a : Foo<string> | ||
|
28 changes: 28 additions & 0 deletions
28
tests/cases/compiler/varianceCantBeStrictWhileStructureIsnt.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,28 @@ | ||
// @strict: false | ||
// @strictFunctionTypes: false | ||
// under non-strict-function-types, all the below should work | ||
interface Foo<T> { | ||
member: (cb: T) => void; | ||
} | ||
|
||
interface Bar<T> { | ||
member: (cb: T) => void; | ||
} | ||
|
||
declare var a: Foo<string>; | ||
declare var b: Foo<"">; | ||
|
||
declare var a2: Bar<string>; | ||
declare var b2: Bar<"">; | ||
|
||
a = b; | ||
b = a; | ||
|
||
a2 = b2; | ||
b2 = a2; | ||
|
||
a = b2; | ||
b = a2; | ||
|
||
a2 = b; | ||
b2 = a; |
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.
Maybe it'd be better to do
false, true
for these?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 already have tests covering the
true
case (as part of much larger tests - basically any variance-related test), just not thefalse
.