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

Weird stack overflow when compiling 4-line code with function, untyped variable, operator and spread operator within cycle #30804

Closed
Veetaha opened this issue Apr 8, 2019 · 5 comments · Fixed by #31098
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

Comments

@Veetaha
Copy link

Veetaha commented Apr 8, 2019

TypeScript Version: 3.0.1+ (including typescript@3.5.0-dev.20190407)

Search Terms:

  • Maximum callstack
  • Stack overflow

Code

let foo = () => {};     // if you remove or change foo definition to not a function, bug disappears
let bar;                // if you add type annotation here, bug disappears
while (1)               // if you remove while, bug disappears
    bar = ~foo(...bar); // if you remove unary or spread operator, bug disappears

//  bar =  || foo(...bar); // though this is a syntax error, it produces stack overflow also

Expected behavior:
Should compile with error report for spreading undefined and/or leaving bar as implicit any

Actual behavior:
Prints Maximum call stack size exceeded.
Or if you run this script with ts-node:

View ts-node stack trace

image

Playground Link:

This is weird, playground from typescriptlang.com seems to work well, but playground from typescript-play.js.org produces the stack overflow as it does locally in my terminal (Ubuntu 18.04.2 LTS). You may see the error for the second playground in your browser console.

Related Issues:
#25149 To some degree

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 9, 2019
@RyanCavanaugh RyanCavanaugh added the Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output label Apr 9, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.5.0 milestone Apr 9, 2019
@andrewbranch
Copy link
Member

@Veetaha can you reproduce this without ts-node? If not, can you please share what version of ts-node and tsconfig-paths you're using?

@Veetaha
Copy link
Author

Veetaha commented Apr 24, 2019

@andrewbranch As I wrote:

Or if you run this script with ts-node:

I meant to use ts-node in order to get the compiler stack trace, because if I reproduce this bug without ts-node, i.e. with tsc I only get "Maximum call stack size exceeded." string printed to the terminal. So yes, you can reproduce this bug with tsc v3.0.1 +

And sorry for tsconfig-paths, those options were left from my production code where I detected this bug, they don't influence the bug.

@Veetaha
Copy link
Author

Veetaha commented Apr 24, 2019

Here is what you get when trying to compile the problem code with tsc:

Peek screenshot

image

@Veetaha
Copy link
Author

Veetaha commented Apr 24, 2019

One more important condition, this bug appears when you use the following minimum tsconfig.json:

{
    "compilerOptions": {
        "noImplicitAny": true,
    }
}

It seems noImplicitAny is the guy to blame here because if you remove that option or set it to false, the bug disappears.

@andrewbranch
Copy link
Member

Ah yep, noImplicitAny is what I was missing in order to repro. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants