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
Fixes #9184
Review
- Which correct matches get the extra unwrap? Those whose dispatch happened to send the object to the right arm, such as
decodeGroupanddecodeNullin pattern_match_json andstringOrOtherin 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.