Files
scriptc/tests/corpus/2404-kill-throw-catch.ts
Chris Tate b9662a34a1 Pin flow-narrowing state routing across merges, loop edges, and do-while (corpus 2390-2423)
- Establishment/containment: miss-first ternary polarity, else-if head exits, bare-block vs alias guards, break/continue exit guards, post-loop re-tests, while-condition guards, born-narrowed declarations (2390-2396)
- Kill routing: branch/switch-arm/reassignment-polarity kills at merges, and kills riding return/break/labeled-break/continue/throw edges (2397-2406)
- Terminality: infinite-loop sealing and re-opening, loop-body returns, stacked and trailing-empty case labels, defaultless exhaustive switches (2407-2411)
- do-while trailing tests under body guards, kills, continue, and break, plus spread-arm ternary lowering shapes, ?? null identity, float-lane bounds, IEEE remainder corners, and parameter null reassignment (2412-2423)
- Order-parity baselines re-recorded for the new entries (pure addition)
2026-07-22 21:40:11 -05:00

24 lines
667 B
TypeScript

// A kill on an always-throwing path is dead on the in-line flow but LIVE inside the catch — the handler must re-test.
interface P { readonly v: number; }
interface BoomError { readonly kind: "boom"; readonly at: number; }
function f(a: P | null, flag: boolean): number {
let p: P | null = a;
if (p === null) return -1;
let n = 0;
try {
if (flag) { p = null; throw { kind: "boom", at: 0 } as BoomError; }
n += p.v;
} catch (err) {
if (p === null) {
n += 1;
} else {
n += p.v;
}
}
if (p === null) return n;
return n + p.v;
}
console.log(f({ v: 4 }, false));
console.log(f({ v: 4 }, true));
console.log(f(null, true));