Merge pull request #9510 from Microsoft/fixSwitchCase
Fix switch case circular reference stack overflow
This commit is contained in:
commit
29ac7e4e3d
4 changed files with 55 additions and 0 deletions
|
@ -551,6 +551,9 @@ namespace ts {
|
|||
case SyntaxKind.CaseBlock:
|
||||
bindCaseBlock(<CaseBlock>node);
|
||||
break;
|
||||
case SyntaxKind.CaseClause:
|
||||
bindCaseClause(<CaseClause>node);
|
||||
break;
|
||||
case SyntaxKind.LabeledStatement:
|
||||
bindLabeledStatement(<LabeledStatement>node);
|
||||
break;
|
||||
|
@ -989,6 +992,14 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function bindCaseClause(node: CaseClause): void {
|
||||
const saveCurrentFlow = currentFlow;
|
||||
currentFlow = preSwitchCaseFlow;
|
||||
bind(node.expression);
|
||||
currentFlow = saveCurrentFlow;
|
||||
forEach(node.statements, bind);
|
||||
}
|
||||
|
||||
function pushActiveLabel(name: string, breakTarget: FlowLabel, continueTarget: FlowLabel): ActiveLabel {
|
||||
const activeLabel = {
|
||||
name,
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchCaseCircularRefeference.ts (1 errors) ====
|
||||
// Repro from #9507
|
||||
|
||||
function f(x: {a: "A", b} | {a: "C", e}) {
|
||||
switch (x.a) {
|
||||
case x:
|
||||
~
|
||||
!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
|
||||
break;
|
||||
}
|
||||
}
|
18
tests/baselines/reference/switchCaseCircularRefeference.js
Normal file
18
tests/baselines/reference/switchCaseCircularRefeference.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
//// [switchCaseCircularRefeference.ts]
|
||||
// Repro from #9507
|
||||
|
||||
function f(x: {a: "A", b} | {a: "C", e}) {
|
||||
switch (x.a) {
|
||||
case x:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//// [switchCaseCircularRefeference.js]
|
||||
// Repro from #9507
|
||||
function f(x) {
|
||||
switch (x.a) {
|
||||
case x:
|
||||
break;
|
||||
}
|
||||
}
|
8
tests/cases/compiler/switchCaseCircularRefeference.ts
Normal file
8
tests/cases/compiler/switchCaseCircularRefeference.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Repro from #9507
|
||||
|
||||
function f(x: {a: "A", b} | {a: "C", e}) {
|
||||
switch (x.a) {
|
||||
case x:
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue