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

Stack overflow in recursive type #20772

Closed
evmar opened this issue Dec 19, 2017 · 3 comments · Fixed by #20400
Closed

Stack overflow in recursive type #20772

evmar opened this issue Dec 19, 2017 · 3 comments · Fixed by #20400
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@evmar
Copy link
Contributor

evmar commented Dec 19, 2017

TypeScript Version: playground, typescript@2.7.0-dev.20171216
Code

type Recur = () => Recur.B;

Expected behavior:
Compile error.

Actual behavior:
Stack overflow.

.../node_modules/typescript/lib/tsc.js:59609
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at resolveEntityName (.../node_modules/typescript/lib/tsc.js:20834:35)
    at resolveEntityName (.../node_modules/typescript/lib/tsc.js:20859:33)
    at resolveTypeReferenceName (.../node_modules/typescript/lib/tsc.js:25382:20)
    at getTypeFromTypeReference (.../node_modules/typescript/lib/tsc.js:25481:30)
    at getTypeFromTypeNode (.../node_modules/typescript/lib/tsc.js:26360:28)
    at getSignatureReturnTypeFromDeclaration (.../node_modules/typescript/lib/tsc.js:24997:24)
    at getSignatureFromDeclaration (.../node_modules/typescript/lib/tsc.js:24964:34)
    at getSignaturesOfSymbol (.../node_modules/typescript/lib/tsc.js:25062:37)
    at resolveAnonymousTypeMembers (.../node_modules/typescript/lib/tsc.js:24311:38)
    at resolveStructuredTypeMembers (.../node_modules/typescript/lib/tsc.js:24458:25)
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Dec 19, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.7 milestone Dec 19, 2017
@DanielRosenwasser
Copy link
Member

Doesn't show up until TypeScript 2.5. This is probably my fault from #17459.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Dec 19, 2017

But actually, this is a symptom of a different issue, so it's really a good thing I did that.

Here's a more direct repro that doesn't only exhibit the stack overflow from trying to give a more helpful error message:

type Recur = () => Recur['B']

@sandersn
Copy link
Member

Fixed by #20400

Structured type resolution did not previously care about recursive type resolution; it was only handled in specific cases. Recursive resolution can happen almost anywhere now, so #20400 changes resolveStructuredTypeMembers to handle it.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 11, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants