You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0822b4d
Browse filesBrowse the repository at this point in the historyBrowse files
Keep cases handled by a default arm out of the arms a switch names (#9010)
Why:
A `switch` on an untagged variant with a `_` arm let the cases it does
not name reach the arms it names: a `Date` matched the object arm, since
only arrays were guarded, and an `@as("lit")` literal matched the string
arm, since the literal test was skipped when the switch names no
literal (#8995).
The `switch (typeof x)` is preceded by a guard sending every instance case
without an arm to the default, as it already did for arrays. The literal test
is skipped only when no literal of the variant would pass the check of a
payload arm. Rules 7 and 9 of the spec state both.
JS modified (an instance handled by the default):
Example:
@unboxed type t = D(Date.t) | R(RegExp.t) | O({x: int}) | S(string) | I(int) | F(int => int)
let f = v => switch v { | O(_) => "O" | S(_) => "S" | _ => "other" }
Before (js):
switch (typeof v) {
case "object" :
return "O";
After (js):
if (v instanceof RegExp || v instanceof Date) {
return "other";
}
switch (typeof v) {
case "object" :
return "O";
JS modified (a literal handled by the default):
Example:
@unboxed type t = | @as("lit") Lit | S(string) | I(int) | B(bool) | O({x: int}) | F(int => int)
let f = v => switch v { | S(_) => "S" | O(_) => "O" | _ => "other" }
Before (js):
switch (typeof v) {
case "string" :
return "S";
After (js):
if (v === "lit") {
return "other";
}
switch (typeof v) {
case "string" :
return "S";
Fixes: #8995
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments