-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Detect circular instantiated types #3316
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
413176b
Use symbols instead of types in infinite instantiation detection
ahejlsberg 46e0ba8
Remove old (and insufficient) instantiation caching
ahejlsberg e336e3a
Adding regression test
ahejlsberg dd8f3c4
Addressing CR feedback
ahejlsberg 87d43aa
Merge branch 'master' into circularInstantiatedTypes
ahejlsberg 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/cyclicGenericTypeInstantiation.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,37 @@ | ||
//// [cyclicGenericTypeInstantiation.ts] | ||
function foo<T>() { | ||
var z = foo<typeof y>(); | ||
var y: { | ||
y2: typeof z | ||
}; | ||
return y; | ||
} | ||
|
||
|
||
function bar<T>() { | ||
var z = bar<typeof y>(); | ||
var y: { | ||
y2: typeof z; | ||
} | ||
return y; | ||
} | ||
|
||
var a = foo<number>(); | ||
var b = bar<number>(); | ||
a = b; | ||
|
||
|
||
//// [cyclicGenericTypeInstantiation.js] | ||
function foo() { | ||
var z = foo(); | ||
var y; | ||
return y; | ||
} | ||
function bar() { | ||
var z = bar(); | ||
var y; | ||
return y; | ||
} | ||
var a = foo(); | ||
var b = bar(); | ||
a = b; |
55 changes: 55 additions & 0 deletions
55
tests/baselines/reference/cyclicGenericTypeInstantiation.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,55 @@ | ||
=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === | ||
function foo<T>() { | ||
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) | ||
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13)) | ||
|
||
var z = foo<typeof y>(); | ||
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) | ||
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) | ||
|
||
var y: { | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) | ||
|
||
y2: typeof z | ||
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12)) | ||
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) | ||
|
||
}; | ||
return y; | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) | ||
} | ||
|
||
|
||
function bar<T>() { | ||
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) | ||
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13)) | ||
|
||
var z = bar<typeof y>(); | ||
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) | ||
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) | ||
|
||
var y: { | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) | ||
|
||
y2: typeof z; | ||
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12)) | ||
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) | ||
} | ||
return y; | ||
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) | ||
} | ||
|
||
var a = foo<number>(); | ||
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) | ||
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) | ||
|
||
var b = bar<number>(); | ||
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) | ||
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) | ||
|
||
a = b; | ||
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) | ||
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) | ||
|
60 changes: 60 additions & 0 deletions
60
tests/baselines/reference/cyclicGenericTypeInstantiation.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/cyclicGenericTypeInstantiation.ts === | ||
function foo<T>() { | ||
>foo : <T>() => { y2: any; } | ||
>T : T | ||
|
||
var z = foo<typeof y>(); | ||
>z : { y2: any; } | ||
>foo<typeof y>() : { y2: any; } | ||
>foo : <T>() => { y2: any; } | ||
>y : { y2: any; } | ||
|
||
var y: { | ||
>y : { y2: any; } | ||
|
||
y2: typeof z | ||
>y2 : { y2: any; } | ||
>z : { y2: any; } | ||
|
||
}; | ||
return y; | ||
>y : { y2: any; } | ||
} | ||
|
||
|
||
function bar<T>() { | ||
>bar : <T>() => { y2: any; } | ||
>T : T | ||
|
||
var z = bar<typeof y>(); | ||
>z : { y2: any; } | ||
>bar<typeof y>() : { y2: any; } | ||
>bar : <T>() => { y2: any; } | ||
>y : { y2: any; } | ||
|
||
var y: { | ||
>y : { y2: any; } | ||
|
||
y2: typeof z; | ||
>y2 : { y2: any; } | ||
>z : { y2: any; } | ||
} | ||
return y; | ||
>y : { y2: any; } | ||
} | ||
|
||
var a = foo<number>(); | ||
>a : { y2: any; } | ||
>foo<number>() : { y2: any; } | ||
>foo : <T>() => { y2: any; } | ||
|
||
var b = bar<number>(); | ||
>b : { y2: any; } | ||
>bar<number>() : { y2: any; } | ||
>bar : <T>() => { y2: any; } | ||
|
||
a = b; | ||
>a = b : { y2: any; } | ||
>a : { y2: any; } | ||
>b : { y2: any; } | ||
|
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,20 @@ | ||
function foo<T>() { | ||
var z = foo<typeof y>(); | ||
var y: { | ||
y2: typeof z | ||
}; | ||
return y; | ||
} | ||
|
||
|
||
function bar<T>() { | ||
var z = bar<typeof y>(); | ||
var y: { | ||
y2: typeof z; | ||
} | ||
return y; | ||
} | ||
|
||
var a = foo<number>(); | ||
var b = bar<number>(); | ||
a = b; |
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.
Can you rename this InstantiatedAnonymous? Or have all the types created by instantiateType take on the flag as well.
Also, it seems to me that References are always Instantiated. To that end, can you OR this flag into the Reference flag as well so the subset / superset relation is clear?
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.
Agreed. 'Instantiated' conveys something entirely different to me. Furthermore, if it is supposed to mean InstantiatedAnonymousTYpe, then i'm surprised that it doesn't include 0x00008000 as part of it.