Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/switchCaseCircularRefeference.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions tests/baselines/reference/switchCaseCircularRefeference.js
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions tests/cases/compiler/switchCaseCircularRefeference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Repro from #9507

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