Skip to content

Commit 9af25b4

Browse files
committed
fix(compiler): visit finally with conservative join so catch-exit path does not inherit try-only abort proof
When catch always exits, the previous code narrowed the flow to the try block's proof before visiting the finally block. Since finally runs on every completion path (including the exiting catch), a state update in finally was incorrectly treated as protected by the try block's abort controllers. Save the handler flow, restore the conservative join (intersection of try and catch proofs) for the finally visit, then narrow for the next statement afterward.
1 parent a3055ae commit 9af25b4

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎packages/octane/src/compiler/strong-mode.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,17 +4354,19 @@ export function analyzeStrongMode(ast, source, filename, options = {}) {
43544354
const afterBlock = effectPolicy.saveFlow();
43554355
effectPolicy.restoreFlow(effectPolicy.joinFlow(before, afterBlock));
43564356
visit(node.handler, scope, phase);
4357+
// `finally` runs on every completion path; visit it with the
4358+
// conservative join before narrowing for the next statement.
4359+
const afterHandler = effectPolicy.saveFlow();
4360+
effectPolicy.restoreFlow(effectPolicy.joinFlow(afterBlock, afterHandler));
4361+
visit(node.finalizer, scope, phase);
43574362
// Only a path that completes normally reaches the next statement.
43584363
const blockExits = branchAlwaysExits(node.block);
43594364
const handlerExits = branchAlwaysExits(node.handler.body);
43604365
if (handlerExits && !blockExits) effectPolicy.restoreFlow(afterBlock);
4361-
else if (blockExits === handlerExits) {
4362-
effectPolicy.restoreFlow(effectPolicy.joinFlow(afterBlock, effectPolicy.saveFlow()));
4363-
}
43644366
} else {
43654367
visit(node.handler, scope, phase);
4368+
visit(node.finalizer, scope, phase);
43664369
}
4367-
visit(node.finalizer, scope, phase);
43684370
return;
43694371
}
43704372
case 'JSXSwitchExpression': {

‎packages/octane/tests/compiler/strong-effects.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ describe('Strong asynchronous effect updates', () => {
228228
'a catch handler after an unsigned request',
229229
`try { await fetch('/a', { signal }); } catch { await api.get(props.id); } setData(1);`,
230230
],
231+
[
232+
'a finally block when catch exits',
233+
`await api.warm(); try { await fetch('/a', { signal }); } catch { return; } finally { setData(1); }`,
234+
],
231235
])('rejects an abort proof that does not cover %s', (_label, body) => {
232236
rejects(app(aborted(body)), FETCH);
233237
});

0 commit comments

Comments
 (0)