diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 140902aa4af..26f16c730fb 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -685,7 +685,7 @@ namespace ts { // post catch/finally state is reachable if // - post try state is reachable - control flow can fall out of try block // - post catch state is reachable - control flow can fall out of catch block - currentReachabilityState = or(postTryState, postCatchState); + currentReachabilityState = n.catchClause ? or(postTryState, postCatchState) : postTryState; } function bindSwitchStatement(n: SwitchStatement): void { diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.js b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.js new file mode 100644 index 00000000000..7f0b89153b5 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.js @@ -0,0 +1,22 @@ +//// [noImplicitReturnsWithProtectedBlocks1.ts] +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + finally { + log("in finally"); + } +} + +//// [noImplicitReturnsWithProtectedBlocks1.js] +function main1() { + try { + return get(); + } + finally { + log("in finally"); + } +} diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.symbols b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.symbols new file mode 100644 index 00000000000..1defb4bbca3 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts === +declare function log(s: string): void; +>log : Symbol(log, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 0)) +>s : Symbol(s, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 21)) + +declare function get(): number; +>get : Symbol(get, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 38)) + +function main1() : number { +>main1 : Symbol(main1, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 1, 31)) + + try { + return get(); +>get : Symbol(get, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 38)) + } + finally { + log("in finally"); +>log : Symbol(log, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.types b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.types new file mode 100644 index 00000000000..90db4fb42e1 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks1.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts === +declare function log(s: string): void; +>log : (s: string) => void +>s : string + +declare function get(): number; +>get : () => number + +function main1() : number { +>main1 : () => number + + try { + return get(); +>get() : number +>get : () => number + } + finally { + log("in finally"); +>log("in finally") : void +>log : (s: string) => void +>"in finally" : string + } +} diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.errors.txt b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.errors.txt new file mode 100644 index 00000000000..a77bd0462cd --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts(4,20): error TS7030: Not all code paths return a value. + + +==== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts (1 errors) ==== + declare function log(s: string): void; + declare function get(): number; + + function main1() : number { + ~~~~~~ +!!! error TS7030: Not all code paths return a value. + try { + return get(); + } + catch(e) { + log("in catch"); + } + finally { + log("in finally"); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.js b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.js new file mode 100644 index 00000000000..857a9686232 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks2.js @@ -0,0 +1,28 @@ +//// [noImplicitReturnsWithProtectedBlocks2.ts] +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + catch(e) { + log("in catch"); + } + finally { + log("in finally"); + } +} + +//// [noImplicitReturnsWithProtectedBlocks2.js] +function main1() { + try { + return get(); + } + catch (e) { + log("in catch"); + } + finally { + log("in finally"); + } +} diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.errors.txt b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.errors.txt new file mode 100644 index 00000000000..56f9c701b55 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts(4,20): error TS7030: Not all code paths return a value. + + +==== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts (1 errors) ==== + declare function log(s: string): void; + declare function get(): number; + + function main1() : number { + ~~~~~~ +!!! error TS7030: Not all code paths return a value. + try { + return get(); + } + catch(e) { + log("in catch"); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.js b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.js new file mode 100644 index 00000000000..a70996983f6 --- /dev/null +++ b/tests/baselines/reference/noImplicitReturnsWithProtectedBlocks3.js @@ -0,0 +1,22 @@ +//// [noImplicitReturnsWithProtectedBlocks3.ts] +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + catch(e) { + log("in catch"); + } +} + +//// [noImplicitReturnsWithProtectedBlocks3.js] +function main1() { + try { + return get(); + } + catch (e) { + log("in catch"); + } +} diff --git a/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts new file mode 100644 index 00000000000..4b2174386fa --- /dev/null +++ b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts @@ -0,0 +1,12 @@ +// @noImplicitReturns: true +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + finally { + log("in finally"); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts new file mode 100644 index 00000000000..fbd12526cf9 --- /dev/null +++ b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts @@ -0,0 +1,15 @@ +// @noImplicitReturns: true +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + catch(e) { + log("in catch"); + } + finally { + log("in finally"); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts new file mode 100644 index 00000000000..1cbb12b1ae0 --- /dev/null +++ b/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts @@ -0,0 +1,12 @@ +// @noImplicitReturns: true +declare function log(s: string): void; +declare function get(): number; + +function main1() : number { + try { + return get(); + } + catch(e) { + log("in catch"); + } +} \ No newline at end of file