-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Defer type comparability check for assertions #53261
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
12 commits
Select commit
Hold shift + click to select a range
6c1d25e
add repro test
gabritto 46c61b3
WIP: defer type comparability check in assertions
gabritto 3a2d005
add test not fixed by change
gabritto 45124b1
Merge branch 'main' into gabritto/issue52813
gabritto 2c4d61c
clean up comments
gabritto d409b7f
test: always call checkExpression
gabritto 469f24d
WIP: use checkExpressionCached
gabritto 421b567
always check expression when checking assertion
gabritto 9e8f424
add checkMode
gabritto 7620056
readd lazy diagnostic call
gabritto fd7d37a
use checkExpression instead of checkExpressionCached
gabritto 5171faf
extract duplicate code into helper
gabritto 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [classVarianceCircularity.ts] | ||
// Issue #52813 | ||
|
||
function f() { | ||
const b = new Bar(); | ||
// Uncomment to create error | ||
console.log(b.Value); | ||
} | ||
|
||
class Bar<T> { | ||
num!: number; | ||
// Or swap these two lines | ||
Field: number = (this as Bar<any>).num; | ||
Value = (this as Bar<any>).num; | ||
} | ||
|
||
//// [classVarianceCircularity.js] | ||
"use strict"; | ||
// Issue #52813 | ||
function f() { | ||
var b = new Bar(); | ||
// Uncomment to create error | ||
console.log(b.Value); | ||
} | ||
var Bar = /** @class */ (function () { | ||
function Bar() { | ||
// Or swap these two lines | ||
this.Field = this.num; | ||
this.Value = this.num; | ||
} | ||
return Bar; | ||
}()); |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/classVarianceCircularity.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,42 @@ | ||
=== tests/cases/compiler/classVarianceCircularity.ts === | ||
// Issue #52813 | ||
|
||
function f() { | ||
>f : Symbol(f, Decl(classVarianceCircularity.ts, 0, 0)) | ||
|
||
const b = new Bar(); | ||
>b : Symbol(b, Decl(classVarianceCircularity.ts, 3, 9)) | ||
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
|
||
// Uncomment to create error | ||
console.log(b.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>b.Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43)) | ||
>b : Symbol(b, Decl(classVarianceCircularity.ts, 3, 9)) | ||
>Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43)) | ||
} | ||
|
||
class Bar<T> { | ||
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
>T : Symbol(T, Decl(classVarianceCircularity.ts, 8, 10)) | ||
|
||
num!: number; | ||
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14)) | ||
|
||
// Or swap these two lines | ||
Field: number = (this as Bar<any>).num; | ||
>Field : Symbol(Bar.Field, Decl(classVarianceCircularity.ts, 9, 17)) | ||
>(this as Bar<any>).num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14)) | ||
>this : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14)) | ||
|
||
Value = (this as Bar<any>).num; | ||
>Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43)) | ||
>(this as Bar<any>).num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14)) | ||
>this : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1)) | ||
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14)) | ||
} |
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/classVarianceCircularity.ts === | ||
// Issue #52813 | ||
|
||
function f() { | ||
>f : () => void | ||
|
||
const b = new Bar(); | ||
>b : Bar<unknown> | ||
>new Bar() : Bar<unknown> | ||
>Bar : typeof Bar | ||
|
||
// Uncomment to create error | ||
console.log(b.Value); | ||
>console.log(b.Value) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>b.Value : number | ||
>b : Bar<unknown> | ||
>Value : number | ||
} | ||
|
||
class Bar<T> { | ||
>Bar : Bar<T> | ||
|
||
num!: number; | ||
>num : number | ||
|
||
// Or swap these two lines | ||
Field: number = (this as Bar<any>).num; | ||
>Field : number | ||
>(this as Bar<any>).num : number | ||
>(this as Bar<any>) : Bar<any> | ||
>this as Bar<any> : Bar<any> | ||
>this : this | ||
>num : number | ||
|
||
Value = (this as Bar<any>).num; | ||
>Value : number | ||
>(this as Bar<any>).num : number | ||
>(this as Bar<any>) : Bar<any> | ||
>this as Bar<any> : Bar<any> | ||
>this : this | ||
>num : number | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/baselines/reference/classVarianceResolveCircularity.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,15 @@ | ||
tests/cases/compiler/classVarianceResolveCircularity.ts(5,5): error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
|
||
|
||
==== tests/cases/compiler/classVarianceResolveCircularity.ts (1 errors) ==== | ||
// Issue #52813 | ||
|
||
class Bar<T> { | ||
num!: number; // Swap to remove error | ||
Value = callme(this).num; | ||
~~~~~ | ||
!!! error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
Field: number = callme(this).num; | ||
} | ||
declare function callme(x: Bar<any>): Bar<any>; | ||
declare function callme(x: object): string; |
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/classVarianceResolveCircularity.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,21 @@ | ||
//// [classVarianceResolveCircularity.ts] | ||
// Issue #52813 | ||
|
||
class Bar<T> { | ||
num!: number; // Swap to remove error | ||
Value = callme(this).num; | ||
Field: number = callme(this).num; | ||
} | ||
declare function callme(x: Bar<any>): Bar<any>; | ||
declare function callme(x: object): string; | ||
|
||
//// [classVarianceResolveCircularity.js] | ||
"use strict"; | ||
// Issue #52813 | ||
var Bar = /** @class */ (function () { | ||
function Bar() { | ||
this.Value = callme(this).num; | ||
this.Field = callme(this).num; | ||
} | ||
return Bar; | ||
}()); |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/classVarianceResolveCircularity.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,34 @@ | ||
=== tests/cases/compiler/classVarianceResolveCircularity.ts === | ||
// Issue #52813 | ||
|
||
class Bar<T> { | ||
>Bar : Symbol(Bar, Decl(classVarianceResolveCircularity.ts, 0, 0)) | ||
>T : Symbol(T, Decl(classVarianceResolveCircularity.ts, 2, 10)) | ||
|
||
num!: number; // Swap to remove error | ||
>num : Symbol(Bar.num, Decl(classVarianceResolveCircularity.ts, 2, 14)) | ||
|
||
Value = callme(this).num; | ||
>Value : Symbol(Bar.Value, Decl(classVarianceResolveCircularity.ts, 3, 17)) | ||
>callme(this).num : Symbol(Bar.num, Decl(classVarianceResolveCircularity.ts, 2, 14)) | ||
>callme : Symbol(callme, Decl(classVarianceResolveCircularity.ts, 6, 1), Decl(classVarianceResolveCircularity.ts, 7, 47)) | ||
>this : Symbol(Bar, Decl(classVarianceResolveCircularity.ts, 0, 0)) | ||
>num : Symbol(Bar.num, Decl(classVarianceResolveCircularity.ts, 2, 14)) | ||
|
||
Field: number = callme(this).num; | ||
>Field : Symbol(Bar.Field, Decl(classVarianceResolveCircularity.ts, 4, 29)) | ||
>callme(this).num : Symbol(Bar.num, Decl(classVarianceResolveCircularity.ts, 2, 14)) | ||
>callme : Symbol(callme, Decl(classVarianceResolveCircularity.ts, 6, 1), Decl(classVarianceResolveCircularity.ts, 7, 47)) | ||
>this : Symbol(Bar, Decl(classVarianceResolveCircularity.ts, 0, 0)) | ||
>num : Symbol(Bar.num, Decl(classVarianceResolveCircularity.ts, 2, 14)) | ||
} | ||
declare function callme(x: Bar<any>): Bar<any>; | ||
>callme : Symbol(callme, Decl(classVarianceResolveCircularity.ts, 6, 1), Decl(classVarianceResolveCircularity.ts, 7, 47)) | ||
>x : Symbol(x, Decl(classVarianceResolveCircularity.ts, 7, 24)) | ||
>Bar : Symbol(Bar, Decl(classVarianceResolveCircularity.ts, 0, 0)) | ||
>Bar : Symbol(Bar, Decl(classVarianceResolveCircularity.ts, 0, 0)) | ||
|
||
declare function callme(x: object): string; | ||
>callme : Symbol(callme, Decl(classVarianceResolveCircularity.ts, 6, 1), Decl(classVarianceResolveCircularity.ts, 7, 47)) | ||
>x : Symbol(x, Decl(classVarianceResolveCircularity.ts, 8, 24)) | ||
|
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/classVarianceResolveCircularity.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,33 @@ | ||
=== tests/cases/compiler/classVarianceResolveCircularity.ts === | ||
// Issue #52813 | ||
|
||
class Bar<T> { | ||
>Bar : Bar<T> | ||
|
||
num!: number; // Swap to remove error | ||
>num : number | ||
|
||
Value = callme(this).num; | ||
>Value : any | ||
>callme(this).num : number | ||
>callme(this) : Bar<any> | ||
>callme : { (x: Bar<any>): Bar<any>; (x: object): string; } | ||
>this : this | ||
>num : number | ||
|
||
Field: number = callme(this).num; | ||
>Field : number | ||
>callme(this).num : number | ||
>callme(this) : Bar<any> | ||
>callme : { (x: Bar<any>): Bar<any>; (x: object): string; } | ||
>this : this | ||
>num : number | ||
} | ||
declare function callme(x: Bar<any>): Bar<any>; | ||
>callme : { (x: Bar<any>): Bar<any>; (x: object): string; } | ||
>x : Bar<any> | ||
|
||
declare function callme(x: object): string; | ||
>callme : { (x: Bar<any>): Bar<any>; (x: object): string; } | ||
>x : object | ||
|
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,16 @@ | ||
// @strict: true | ||
|
||
// Issue #52813 | ||
|
||
function f() { | ||
const b = new Bar(); | ||
// Uncomment to create error | ||
console.log(b.Value); | ||
} | ||
|
||
class Bar<T> { | ||
num!: number; | ||
// Or swap these two lines | ||
Field: number = (this as Bar<any>).num; | ||
Value = (this as Bar<any>).num; | ||
} |
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,11 @@ | ||
// @strict: true | ||
|
||
// Issue #52813 | ||
|
||
class Bar<T> { | ||
num!: number; // Swap to remove error | ||
Value = callme(this).num; | ||
Field: number = callme(this).num; | ||
} | ||
declare function callme(x: Bar<any>): Bar<any>; | ||
declare function callme(x: object): string; |
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 an example where this PR's approach doesn't solve the circularity problem.
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.
I assume you mean the other test with the function calls rather than expressions, since that's the one that still has an error. :) If you want, you should file an issue about the other form, so the issue can still get backlog'd, if you want to consider looking into a broader fix in the future after this PR marks the original issue as fixed.