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 alias + lookup type #14837

Closed
HerringtonDarkholme opened this issue Mar 24, 2017 · 5 comments · Fixed by #15011
Closed

stack overflow in recursive type alias + lookup type #14837

HerringtonDarkholme opened this issue Mar 24, 2017 · 5 comments · Fixed by #15011
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@HerringtonDarkholme
Copy link
Contributor

HerringtonDarkholme commented Mar 24, 2017

Extracted from #14833

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code

type Foo<T extends "true", B> = { "true": Foo<T, Foo<T, B>> }[T];
let f: Foo<"true", {}> = null!;

Expected behavior:
An error reporting cyclic dependency.

Actual behavior:

Throw RangeError: Maximum call stack size exceeded

@HerringtonDarkholme HerringtonDarkholme changed the title [BUG] stack overflow in recursive type alias + lookup type stack overflow in recursive type alias + lookup type Mar 24, 2017
@mhegazy mhegazy added Bug A bug in TypeScript and removed Bug A bug in TypeScript labels Mar 24, 2017
@mhegazy mhegazy modified the milestone: TypeScript 2.3 Mar 24, 2017
@hediet
Copy link
Member

hediet commented Mar 24, 2017

But without this, TypeScript's type system is most probably not turing complete any more :(

@RyanCavanaugh
Copy link
Member

We should just detect ahead of time whether or not a given type relation check will eventually halt

@HerringtonDarkholme
Copy link
Contributor Author

HerringtonDarkholme commented Mar 25, 2017

I've seen similar bug in Scala since 2.8 and fixed in 2.11 or so. Other (industry) languages also prioritize consistency over power.

To achieve type system consistence we need to, sadly, abstain from Turing completeness.

@hediet Your proof is very amazing and smart!

@HerringtonDarkholme
Copy link
Contributor Author

HerringtonDarkholme commented Mar 25, 2017

Another piece of strange code, it compiles but should not.

type Foo<T extends "true"> = { "true": Foo<'false'> }[T]; // should report error on 'false'
let f: Foo<"true"> = null!;

@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned sandersn Apr 4, 2017
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 4, 2017
@mattdsteele
Copy link

@RyanCavanaugh Just an FYI, #14837 (comment) literally made me laugh out loud. Cheers! 🎉

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 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.

7 participants