Skip to content

Commit b922496

Browse files
committed
add test for try/finally with return+throw and non-empty finally body
1 parent 32a7fc0 commit b922496

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/unit/error.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,27 @@ test("try/finally runs finally side effect before rethrow", () => {
460460
`.expectToMatchJsResult();
461461
});
462462

463+
test("try/finally with return and throw paths and non-empty finally body", () => {
464+
util.testFunction`
465+
let sideEffect = false;
466+
function foo(shouldReturn: boolean) {
467+
try {
468+
if (shouldReturn) return "ok";
469+
throw "err";
470+
} finally {
471+
sideEffect = true;
472+
}
473+
}
474+
const results: any[] = [];
475+
results.push(foo(true));
476+
results.push(sideEffect);
477+
sideEffect = false;
478+
try { foo(false); } catch(e) { results.push(e); }
479+
results.push(sideEffect);
480+
return results;
481+
`.expectToMatchJsResult();
482+
});
483+
463484
test("try/finally rethrow with non-string error", () => {
464485
util.testFunction`
465486
function foo() {

0 commit comments

Comments
 (0)