diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b45af24d4d198..b7852a64d04de 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -551,6 +551,9 @@ namespace ts { case SyntaxKind.CaseBlock: bindCaseBlock(node); break; + case SyntaxKind.CaseClause: + bindCaseClause(node); + break; case SyntaxKind.LabeledStatement: bindLabeledStatement(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, diff --git a/tests/baselines/reference/switchCaseCircularRefeference.errors.txt b/tests/baselines/reference/switchCaseCircularRefeference.errors.txt new file mode 100644 index 0000000000000..9ee571de468ce --- /dev/null +++ b/tests/baselines/reference/switchCaseCircularRefeference.errors.txt @@ -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; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseCircularRefeference.js b/tests/baselines/reference/switchCaseCircularRefeference.js new file mode 100644 index 0000000000000..7ef901511cf3e --- /dev/null +++ b/tests/baselines/reference/switchCaseCircularRefeference.js @@ -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; + } +} diff --git a/tests/cases/compiler/switchCaseCircularRefeference.ts b/tests/cases/compiler/switchCaseCircularRefeference.ts new file mode 100644 index 0000000000000..060b90fa8a1cd --- /dev/null +++ b/tests/cases/compiler/switchCaseCircularRefeference.ts @@ -0,0 +1,8 @@ +// Repro from #9507 + +function f(x: {a: "A", b} | {a: "C", e}) { + switch (x.a) { + case x: + break; + } +} \ No newline at end of file