Files
scriptc/tests/corpus/2425-elseif-head-exit-narrow.ts
Chris Tate 93fdc9fbc6 Adversarial flow-narrowing corpus: 34 fixtures
- Narrowing establishment/containment, kill routing, sibling-arm restoration
- Terminality, do-while, ternary lowering, nullish and IEEE corners
- All byte-exact against Node on both backends; two fixtures renumbered 2424/2425
2026-07-22 22:09:48 -05:00

15 lines
463 B
TypeScript

// An exiting null guard heading an if/else-if chain narrows every read after the whole statement, including flows through a middle arm that never mentions the value.
interface P { readonly v: number; }
function pick(x: P | null, flag: boolean): number {
let n = 1;
if (x === null) {
return -1;
} else if (flag) {
n = 2;
}
return x.v + n;
}
console.log(pick(null, true));
console.log(pick({ v: 10 }, true));
console.log(pick({ v: 10 }, false));