Semantic Diff

#9206 Unwrap Some of a variant with an undefined case before matching it

2 commits

85853119fd52b3ec4ef13f8726303167df7c0ac3..pr-9206

6ddec83bf · cknitt + Claude · Nov 03, 2026, 18:34 UTC

Unwrap Some of a variant with an undefined case before matching it

Why

A switch on option<t>, where t has an @as(undefined) case, read the payload without unwrapping the object that represents Some of that case whenever the payload patterns were wildcards, literal cases or untagged cases, assuming each would reject the object with its own test. But the switch on the payload gets a case for every constructor, from the match's default rows for those the patterns don't name, and takes its last case without a test, so Some(U) reached the arm of another case or no arm at all. The payload is now unwrapped unless its type rules out undefined.

modifiedJS switch on an option of an untagged variant

@unboxed type t = @as(undefined) U | S(string) | I(int) let g = (x: option<t>) =>  switch x {  | None => "None"  | Some(S(_)) => "SS"  | Some(I(_)) => "SI"  | Some(_) => "SU"  }
js
Before g(Some(U)) returns "SI"
After g(Some(U)) returns "SU"
function g(x) {function g(x) { if (x !== undefined) { if (x === undefined) { return "SU"; } else if (typeof x === "string") { return "SS"; } else { return "SI"; } } else { if (x === undefined) { return "None"; return "None"; } } let tmp = Primitive_option.valFromOption(x); if (tmp === undefined) { return "SU"; } else if (typeof tmp === "string") { return "SS"; } else { return "SI"; }}}

Fixes #9184

Review

  • Which correct matches get the extra unwrap? Those whose dispatch happened to send the object to the right arm, such as decodeGroup and decodeNull in pattern_match_json and stringOrOther in pm_opt_fields_mixed_test. Telling them apart needs the finished switch, so the patterns no longer decide; only payload types that can't hold undefined skip the unwrap, as before.
296035416 · cknitt + Claude · Nov 05, 2026, 05:55 UTC

Drop the changelog fragment for a regression no release has

The shortcut this branch removes came with #8842, which no release contains: 12.3.1 and 13.0.0-alpha.6 unwrap the payload whenever its type can contain undefined, so they take the right arm.