Skip to content

Regression Test for RangeError Crash #59594

Closed
@LukeAbby

Description

@LukeAbby

🔎 Search Terms

RangeError regression test

🕗 Version & Regression Information

Somewhat unconventionally this particular issue was actually already fixed in 71fb864 but it's broken before c8a7d58. It shows up in TypeScript 5.5.4 but not TypeScript 5.4

I'm only still reporting this issue because it doesn't look like the commit that happened to fix it contained any regression tests for this crash or anything. As far as I can tell the fact that this crash was fixed by complete chance and I want to make sure that this doesn't happen again.

⏯ Playground Link

No response

💻 Code

This doesn't seem to crash in the Playground, presumably because it resolves differently than tsc and avoids the RangeError, but maybe I messed something up.

TSConfig:

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": false,
    "outDir": "./out"
  }
}

Minimal reproduction JavaScript file (run with checkJS):

var a$b = {};
var c, d;
d = a$b;
while (d !== a$b);
while ((c = a$b != a$b)) c.e;

I managed to take a much larger file and reduce it using CReduce, hence why it's so contrived. However this happened in the real world, I became aware of this while helping out with peggyjs/peggy#538. The full file causing the error is this: https://github.com/peggyjs/peggy/blob/4036dabd40bdb318876ba0f3ac6fd5b0ae317176/lib/parser.js

Alternatively use the zipped reproduction project - to reproduce run npm install and then ./node_modules/typescript/bin/tsc.

When I run with TypeScript == 5.5.4 this crashes, though on TypeScript@main it doesn't so as already mentioned it's already been fixed. This is the traceback:

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

RangeError: Maximum call stack size exceeded
    at createObjectType (node_modules/typescript/lib/tsc.js:48681:28)
    at createAnonymousType (node_modules/typescript/lib/tsc.js:48728:37)
    at getJSContainerObjectType (node_modules/typescript/lib/tsc.js:54416:18)
    at getTypeForVariableLikeDeclaration (node_modules/typescript/lib/tsc.js:54202:37)
    at getWidenedTypeForVariableLikeDeclaration (node_modules/typescript/lib/tsc.js:54654:48)
    at getTypeOfVariableOrParameterOrPropertyWorker (node_modules/typescript/lib/tsc.js:54802:14)
    at getTypeOfVariableOrParameterOrProperty (node_modules/typescript/lib/tsc.js:54735:20)
    at getTypeOfSymbol (node_modules/typescript/lib/tsc.js:55064:14)
    at getNarrowedTypeOfSymbol (node_modules/typescript/lib/tsc.js:69809:18)
    at checkIdentifier (node_modules/typescript/lib/tsc.js:69948:16)

Terminal session running the reproduction:
RangeError Crash

🙁 Actual behavior

This (used to) crash and doesn't seem to have a regression test.

🙂 Expected behavior

No crash

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions