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
6 changes: 5 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,11 @@ namespace ts {
currentFlow = preTryFlow;
bind(node.finallyBlock);
}
currentFlow = finishFlowLabel(postFinallyLabel);
// if try statement has finally block and flow after finally block is unreachable - keep it
// otherwise use whatever flow was accumulated at postFinallyLabel
if (!node.finallyBlock || !(currentFlow.flags & FlowFlags.Unreachable)) {
currentFlow = finishFlowLabel(postFinallyLabel);
}
}

function bindSwitchStatement(node: SwitchStatement): void {
Expand Down
27 changes: 27 additions & 0 deletions tests/baselines/reference/unreachableFlowAfterFinally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [unreachableFlowAfterFinally.ts]

function f() {
let x = 100;
try {
throw "WAT"
}
catch (e) {

}
finally {
return x;
}
}

//// [unreachableFlowAfterFinally.js]
function f() {
var x = 100;
try {
throw "WAT";
}
catch (e) {
}
finally {
return x;
}
}
20 changes: 20 additions & 0 deletions tests/baselines/reference/unreachableFlowAfterFinally.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== tests/cases/compiler/unreachableFlowAfterFinally.ts ===

function f() {
>f : Symbol(f, Decl(unreachableFlowAfterFinally.ts, 0, 0))

let x = 100;
>x : Symbol(x, Decl(unreachableFlowAfterFinally.ts, 2, 7))

try {
throw "WAT"
}
catch (e) {
>e : Symbol(e, Decl(unreachableFlowAfterFinally.ts, 6, 11))

}
finally {
return x;
>x : Symbol(x, Decl(unreachableFlowAfterFinally.ts, 2, 7))
}
}
22 changes: 22 additions & 0 deletions tests/baselines/reference/unreachableFlowAfterFinally.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/compiler/unreachableFlowAfterFinally.ts ===

function f() {
>f : () => number

let x = 100;
>x : number
>100 : 100

try {
throw "WAT"
>"WAT" : "WAT"
}
catch (e) {
>e : any

}
finally {
return x;
>x : number
}
}
14 changes: 14 additions & 0 deletions tests/cases/compiler/unreachableFlowAfterFinally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @noImplicitReturns: true

function f() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noImplicitReturns: true

let x = 100;
try {
throw "WAT"
}
catch (e) {

}
finally {
return x;
}
}