Skip to content
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

Detect circular instantiated types #3316

Merged
merged 5 commits into from
Jun 3, 2015
Merged

Conversation

ahejlsberg
Copy link
Member

Fixes #3309 (and revises fix for #3237).

This PR switches our isDeeplyNestedGeneric function to track both type references and instantiated anonymous types. The key change is that we use the symbol associated with the type as the tracked identity (which is always the symbol of the type being instantiated). We likewise now use symbols to track cyclic anonymous types in the type-to-string logic.

The PR removes the anonymous type instantiation caching implemented in #3239 as it is no longer necessary.

if (type.flags & TypeFlags.Reference && depth >= 10) {
let target = (<TypeReference>type).target;
if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) {
let symbol = type.symbol;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary because you only refer to symbol once

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean. It is referenced in a loop that will run at least 10 times (as we known depth >= 10).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean just once lexically. I didn't know the runtime references count individually wrt to local vars.

@JsonFreeman
Copy link
Contributor

👍

Conflicts:
	src/compiler/checker.ts
	src/compiler/types.ts
ahejlsberg added a commit that referenced this pull request Jun 3, 2015
@ahejlsberg ahejlsberg merged commit b551177 into master Jun 3, 2015
@ahejlsberg ahejlsberg deleted the circularInstantiatedTypes branch June 3, 2015 22:08
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack overflow for infinitely recursive anonymous type
4 participants