Skip to content

Maximum call stack size exceeded if the variable is used in a condition before its declaration using property accessΒ #45830

@hikiko4ern

Description

@hikiko4ern

Bug Report

πŸ”Ž Search Terms

  • Maximum call stack size exceeded
  • property access call

πŸ•— Version & Regression Information

Works on 4.3.5, crashes on 4.4.0-beta, 4.4.1-rc, 4.4.2, 4.4.3, 4.5.0-dev.20210910.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const obj = {
    fn: () => true
};

if (a) { } // crashes if `a` is used in the condition

const a = obj.fn();

There will be no crash if a is declared without accessing the obj property

const obj = {
    fn: () => true
};

const callFn = () => obj.fn();

if (a) { } // now it doesn't crash

const a = callFn();

πŸ™ Actual behavior

$ yarn tsc test.ts

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

RangeError: Maximum call stack size exceeded
    at /project/node_modules/typescript/lib/tsc.js:9125:63
    at getCombinedFlags (/project/node_modules/typescript/lib/tsc.js:9103:21)
    at Object.getCombinedNodeFlags (/project/node_modules/typescript/lib/tsc.js:9125:16)
    at getDeclarationNodeFlagsFromSymbol (/project/node_modules/typescript/lib/tsc.js:59070:44)
    at checkIdentifier (/project/node_modules/typescript/lib/tsc.js:56890:46)
    at checkExpressionWorker (/project/node_modules/typescript/lib/tsc.js:63702:28)
    at checkExpression (/project/node_modules/typescript/lib/tsc.js:63657:38)
    at checkNonNullExpression (/project/node_modules/typescript/lib/tsc.js:59167:37)
    at checkPropertyAccessExpression (/project/node_modules/typescript/lib/tsc.js:59212:85)
    at checkExpressionWorker (/project/node_modules/typescript/lib/tsc.js:63734:28)

πŸ™‚ Expected behavior

Should report the error Block-scoped variable 'a' used before its declaration.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions