Semantic Diff

#9418 Keep the default of a dense int switch ending in an unreachable case

1 commit

45dba2c9137d6be765c1d8d45f287d739e028498..pr-9418

5052dbef1 · illusionalsagacity · Nov 23, 2026, 20:40 UTC

Keep the default of a dense int switch ending in an unreachable case

Why

When the highest cases of a dense int or char switch map to the failure action (for example an unreachable case whose action becomes the exit), the trailing failure interval stopped at the last case instead of the top of the range. Values above it were left out of the interval table, so the generated JS switch had no default and returned undefined for them. The trailing failure interval now runs to the top of the range. The store that reserves action index 0 for the failure action moves out of an assert, so it no longer depends on assertions being compiled in.

modifiedJS dense switch with an unreachable last case

@warning("-11")let f = (n: int, flag: bool) =>  switch (n, flag) {  | (_, true) => 0  | (0, _) => 10  | (1, _) => 11  | (2, _) => 12  | (3, _) => 13  | (4, _) => 14  | (5, true) => 15  | _ => 99  }
js
Before
After
function f(n, flag) {function f(n, flag) { if (flag) { if (flag) { return 0; return 0; } } if (n < 0) { return 99; } switch (n) { switch (n) { case 0 : case 0 : return 10; return 10; case 1 : case 1 : return 11; return 11; case 2 : case 2 : return 12; return 12; case 3 : case 3 : return 13; return 13; case 4 : case 4 : return 14; return 14; case 5 : default: return 99; return 99; } }}}

Review

  • Does binding the failure store outside the assert change any output? No; asserts are compiled in today, and it only matters for a build with -noassert.