Skip to content

STOFL if narrowed variable is mentioned in 'case' condition expression #9507

@zhuravlikjb

Description

@zhuravlikjb

A very simple repro:

function f(x: {a: "A", b} | {a: "C", e}) {
    switch (x.a) {
    case x:
        break;
    }
}

that results in stack overflow:

C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript>node built\local\tsc.js hello.ts
C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:37776
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at Object.hasOwnProperty (native)
    at Object.hasProperty (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:1060:31)
    at getPropertyOfUnionOrIntersectionType (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:17227:20)
    at getPropertyOfType (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:17255:24)
    at getTypeOfPropertyOfType (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:16003:24)
    at narrowTypeBySwitchOnDiscriminant (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:20364:32)
    at getTypeAtSwitchClause (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:20207:24)
    at getTypeAtFlowNode (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:20145:32)
    at getFlowTypeOfReference (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:20118:26)
    at checkIdentifier (C:\Users\Anton.Lobov\Desktop\ts_new\TypeScript\built\local\tsc.js:20577:28)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions