do not reset current flow after processing finally block if it was unreachable (#11310)
* do not reset current flow after processing finally block if it was unreachable * fix tests
This commit is contained in:
parent
9afb07de5a
commit
4800464ed6
5 changed files with 88 additions and 1 deletions
|
@ -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 {
|
||||
|
|
27
tests/baselines/reference/unreachableFlowAfterFinally.js
Normal file
27
tests/baselines/reference/unreachableFlowAfterFinally.js
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
tests/baselines/reference/unreachableFlowAfterFinally.types
Normal file
22
tests/baselines/reference/unreachableFlowAfterFinally.types
Normal file
|
@ -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
tests/cases/compiler/unreachableFlowAfterFinally.ts
Normal file
14
tests/cases/compiler/unreachableFlowAfterFinally.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
// @noImplicitReturns: true
|
||||
|
||||
function f() {
|
||||
let x = 100;
|
||||
try {
|
||||
throw "WAT"
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
finally {
|
||||
return x;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue