check that default clause is non-empty in reachability checks
This commit is contained in:
parent
f07b4ba9d7
commit
92938cd8df
|
@ -912,8 +912,8 @@ namespace ts {
|
|||
preSwitchCaseFlow = currentFlow;
|
||||
bind(node.caseBlock);
|
||||
addAntecedent(postSwitchLabel, currentFlow);
|
||||
const hasDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause);
|
||||
if (!hasDefault) {
|
||||
const hasNonEmptyDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause && c.statements.length);
|
||||
if (!hasNonEmptyDefault) {
|
||||
addAntecedent(postSwitchLabel, preSwitchCaseFlow);
|
||||
}
|
||||
currentBreakTarget = saveBreakTarget;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//// [reachabilityCheckWithEmptyDefault.ts]
|
||||
declare function print(s: string): void;
|
||||
function foo(x: any) {
|
||||
switch(x) {
|
||||
case 1: return;
|
||||
default:
|
||||
}
|
||||
print('1');
|
||||
}
|
||||
|
||||
//// [reachabilityCheckWithEmptyDefault.js]
|
||||
function foo(x) {
|
||||
switch (x) {
|
||||
case 1: return;
|
||||
default:
|
||||
}
|
||||
print('1');
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts ===
|
||||
declare function print(s: string): void;
|
||||
>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0))
|
||||
>s : Symbol(s, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 23))
|
||||
|
||||
function foo(x: any) {
|
||||
>foo : Symbol(foo, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 40))
|
||||
>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13))
|
||||
|
||||
switch(x) {
|
||||
>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13))
|
||||
|
||||
case 1: return;
|
||||
default:
|
||||
}
|
||||
print('1');
|
||||
>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0))
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts ===
|
||||
declare function print(s: string): void;
|
||||
>print : (s: string) => void
|
||||
>s : string
|
||||
|
||||
function foo(x: any) {
|
||||
>foo : (x: any) => void
|
||||
>x : any
|
||||
|
||||
switch(x) {
|
||||
>x : any
|
||||
|
||||
case 1: return;
|
||||
>1 : number
|
||||
|
||||
default:
|
||||
}
|
||||
print('1');
|
||||
>print('1') : void
|
||||
>print : (s: string) => void
|
||||
>'1' : string
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
declare function print(s: string): void;
|
||||
function foo(x: any) {
|
||||
switch(x) {
|
||||
case 1: return;
|
||||
default:
|
||||
}
|
||||
print('1');
|
||||
}
|
Loading…
Reference in a new issue