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 4245a93
Browse filesBrowse the repository at this point in the historyBrowse files
Keep class checks away from primitives and default-arm cases
Why:
Two forms still ran class checks on primitives: the two-arm `if`, with
the class arm declared first, and the literal test, in its form of
negated payload checks. And the guard that sends instance cases without
an arm to the default (#9010) knew only object instances, while a
declared class can have callable instances, and its class checks ran
before the primitive arms.
Of a class arm and an arm of another kind, the two-arm form checks the
other one. A variant with class cases tests its literals by comparison. The
guard for instance cases without an arm also protects a function arm from
class instances, and when the guard has class checks, the primitive arms are
tested first. The spec's rule 10 example of an unchecked branch changes
accordingly: with `PPromise(promise<int>) | PFloat(float)`, the float case
is checked, so a thenable that is not a `Promise` lands in `PPromise`.
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):
if (v instanceof RegExp || v instanceof Date) {
return "other";
}
switch (typeof v) {
case "object" :
return "O";
case "string" :
return "S";
After (js):
switch (typeof v) {
case "string" :
return "S";
default:
if (v instanceof RegExp || v instanceof Date) {
return "other";
}
switch (typeof v) {
case "object" :
return "O";
JS modified (two arms):
Example:
@unboxed type t = W(weird) | S(string)
Before (js): if (v instanceof Weird) { return "W"; } else { return "S"; }
After (js): if (typeof v === "string") { return "S"; } else { return "W"; }
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
Mocha.test("an instance handled by the default is not an object case",()=>{
40
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 31, characters 7-14","other",objectOrString(id(newDate())));
41
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 32, characters 7-14","other",objectOrString(id(/a/)));
42
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 33, characters 7-14","O",objectOrString(id({
78
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 71, characters 7-14","other",objectOrString(id(newDate())));
79
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 72, characters 7-14","other",objectOrString(id(/a/)));
80
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 73, characters 7-14","O",objectOrString(id({
43
81
x: 1
44
82
})));
45
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 34, characters 7-14","S",objectOrString(id("s")));
46
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 35, characters 7-14","other",objectOrString(id(1)));
83
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 74, characters 7-14","S",objectOrString(id("s")));
84
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 75, characters 7-14","other",objectOrString(id(1)));
47
85
});
48
86
Mocha.test("a literal handled by the default is not a string case",()=>{
49
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 39, characters 7-14","other",textOrRecord(id("lit")));
50
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 40, characters 7-14","text",textOrRecord(id("lit2")));
51
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 41, characters 7-14","record",textOrRecord(id({
87
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 79, characters 7-14","other",textOrRecord(id("lit")));
88
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 80, characters 7-14","text",textOrRecord(id("lit2")));
89
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 81, characters 7-14","record",textOrRecord(id({
52
90
x: 1
53
91
})));
54
-
Test_utils.eq("File \"untagged_default_arm_test.res\", line 42, characters 7-14","other",textOrRecord(id(1)));
92
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 82, characters 7-14","other",textOrRecord(id(1)));
93
+
});
94
+
Mocha.test("primitives skip class checks in the two-arm form",()=>Test_utils.eq("File \"untagged_default_arm_test.res\", line 86, characters 7-14","name",twoArmsKind(id("a"))));
95
+
Mocha.test("literals skip class checks",()=>{
96
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 90, characters 7-14","one",withLiteralsKind(id(1)));
97
+
Test_utils.eq("File \"untagged_default_arm_test.res\", line 91, characters 7-14","name",withLiteralsKind(id("a")));
0 commit comments