Files
scriptc/tests/corpus/2420-nullish-null-identity.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

17 lines
511 B
TypeScript

// x ?? null on a T | null value keeps the null arm — the identity default does not fold the union away, and the guard after it still unwraps.
interface V { readonly v: number; }
function f(q: V | null): number {
const picked = q ?? null;
if (picked === null) return -1;
return picked.v;
}
function g(m: number | null): number {
const picked = m ?? null;
if (picked === null) return -1;
return picked + 1;
}
console.log(f({ v: 6 }));
console.log(f(null));
console.log(g(0));
console.log(g(null));