Skip to content

Commit a236b78

Browse files
committed
only apply to untagged variants
1 parent 74ea0ff commit a236b78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1161
-958
lines changed

compiler/core/lam_compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ let compile output_prefix =
749749
use_compile_literal_cases sw_blocks ~get_tag:get_block_tag
750750
in
751751
match (qconsts, qblocks) with
752-
| Some consts_cases, Some blocks_cases when false ->
752+
| Some consts_cases, Some blocks_cases when untagged ->
753753
let untagged_cases = consts_cases @ blocks_cases in
754754
let z =
755755
compile_untagged_cases ~cxt ~switch_exp:e ~block_cases

lib/es6/Intl_NumberFormat_Grouping.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import * as Type from "./Type.js";
44

55
function parseJsValue(value) {
66
let value$1 = Type.Classify.classify(value);
7-
switch (typeof value$1) {
7+
if (typeof value$1 !== "object") {
8+
return;
9+
}
10+
switch (value$1.TAG) {
811
case "Bool" :
912
return {
1013
NAME: "bool",

lib/es6/Primitive_module.js

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,35 @@ function init(loc, shape) {
1010
};
1111
};
1212
let loop = (shape, struct_, idx) => {
13-
switch (typeof shape) {
14-
case "Function" :
15-
case "Lazy" :
16-
struct_[idx] = undef_module;
17-
return;
18-
case "Class" :
19-
struct_[idx] = [
20-
undef_module,
21-
undef_module,
22-
undef_module,
23-
0
24-
];
25-
return;
26-
case "Module" :
27-
let comps = shape._0;
28-
let v = {};
29-
struct_[idx] = v;
30-
let len = comps.length;
31-
for (let i = 0; i < len; ++i) {
32-
let match = comps[i];
33-
loop(match[0], v, match[1]);
34-
}
35-
return;
36-
case "Value" :
13+
if (typeof shape !== "object") {
14+
switch (shape) {
15+
case "Function" :
16+
case "Lazy" :
17+
struct_[idx] = undef_module;
18+
return;
19+
case "Class" :
20+
struct_[idx] = [
21+
undef_module,
22+
undef_module,
23+
undef_module,
24+
0
25+
];
26+
return;
27+
}
28+
} else {
29+
if (shape.TAG !== "Module") {
3730
struct_[idx] = shape._0;
3831
return;
32+
}
33+
let comps = shape._0;
34+
let v = {};
35+
struct_[idx] = v;
36+
let len = comps.length;
37+
for (let i = 0; i < len; ++i) {
38+
let match = comps[i];
39+
loop(match[0], v, match[1]);
40+
}
41+
return;
3942
}
4043
};
4144
let res = {};
@@ -46,27 +49,41 @@ function init(loc, shape) {
4649

4750
function update(shape, o, n) {
4851
let aux = (shape, o, n, parent, i) => {
49-
switch (typeof shape) {
50-
case "Function" :
51-
parent[i] = n;
52-
return;
53-
case "Lazy" :
54-
case "Class" :
55-
Object.assign(o, n);
56-
return;
57-
case "Module" :
58-
let comps = shape._0;
59-
for (let i$1 = 0, i_finish = comps.length; i$1 < i_finish; ++i$1) {
60-
let match = comps[i$1];
61-
let name = match[1];
62-
aux(match[0], o[name], n[name], o, name);
63-
}
64-
return;
65-
case "Value" :
52+
if (typeof shape !== "object") {
53+
switch (shape) {
54+
case "Function" :
55+
parent[i] = n;
56+
return;
57+
case "Lazy" :
58+
case "Class" :
59+
Object.assign(o, n);
60+
return;
61+
}
62+
} else {
63+
if (shape.TAG !== "Module") {
6664
return;
65+
}
66+
let comps = shape._0;
67+
for (let i$1 = 0, i_finish = comps.length; i$1 < i_finish; ++i$1) {
68+
let match = comps[i$1];
69+
let name = match[1];
70+
aux(match[0], o[name], n[name], o, name);
71+
}
72+
return;
6773
}
6874
};
69-
if ("Module") {
75+
if (typeof shape !== "object") {
76+
throw {
77+
RE_EXN_ID: "Assert_failure",
78+
_1: [
79+
"Primitive_module.res",
80+
68,
81+
9
82+
],
83+
Error: new Error()
84+
};
85+
}
86+
if (shape.TAG === "Module") {
7087
let comps = shape._0;
7188
for (let i = 0, i_finish = comps.length; i < i_finish; ++i) {
7289
let match = comps[i];

lib/js/Intl_NumberFormat_Grouping.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ let Type = require("./Type.js");
44

55
function parseJsValue(value) {
66
let value$1 = Type.Classify.classify(value);
7-
switch (typeof value$1) {
7+
if (typeof value$1 !== "object") {
8+
return;
9+
}
10+
switch (value$1.TAG) {
811
case "Bool" :
912
return {
1013
NAME: "bool",

lib/js/Primitive_module.js

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,35 @@ function init(loc, shape) {
1010
};
1111
};
1212
let loop = (shape, struct_, idx) => {
13-
switch (typeof shape) {
14-
case "Function" :
15-
case "Lazy" :
16-
struct_[idx] = undef_module;
17-
return;
18-
case "Class" :
19-
struct_[idx] = [
20-
undef_module,
21-
undef_module,
22-
undef_module,
23-
0
24-
];
25-
return;
26-
case "Module" :
27-
let comps = shape._0;
28-
let v = {};
29-
struct_[idx] = v;
30-
let len = comps.length;
31-
for (let i = 0; i < len; ++i) {
32-
let match = comps[i];
33-
loop(match[0], v, match[1]);
34-
}
35-
return;
36-
case "Value" :
13+
if (typeof shape !== "object") {
14+
switch (shape) {
15+
case "Function" :
16+
case "Lazy" :
17+
struct_[idx] = undef_module;
18+
return;
19+
case "Class" :
20+
struct_[idx] = [
21+
undef_module,
22+
undef_module,
23+
undef_module,
24+
0
25+
];
26+
return;
27+
}
28+
} else {
29+
if (shape.TAG !== "Module") {
3730
struct_[idx] = shape._0;
3831
return;
32+
}
33+
let comps = shape._0;
34+
let v = {};
35+
struct_[idx] = v;
36+
let len = comps.length;
37+
for (let i = 0; i < len; ++i) {
38+
let match = comps[i];
39+
loop(match[0], v, match[1]);
40+
}
41+
return;
3942
}
4043
};
4144
let res = {};
@@ -46,27 +49,41 @@ function init(loc, shape) {
4649

4750
function update(shape, o, n) {
4851
let aux = (shape, o, n, parent, i) => {
49-
switch (typeof shape) {
50-
case "Function" :
51-
parent[i] = n;
52-
return;
53-
case "Lazy" :
54-
case "Class" :
55-
Object.assign(o, n);
56-
return;
57-
case "Module" :
58-
let comps = shape._0;
59-
for (let i$1 = 0, i_finish = comps.length; i$1 < i_finish; ++i$1) {
60-
let match = comps[i$1];
61-
let name = match[1];
62-
aux(match[0], o[name], n[name], o, name);
63-
}
64-
return;
65-
case "Value" :
52+
if (typeof shape !== "object") {
53+
switch (shape) {
54+
case "Function" :
55+
parent[i] = n;
56+
return;
57+
case "Lazy" :
58+
case "Class" :
59+
Object.assign(o, n);
60+
return;
61+
}
62+
} else {
63+
if (shape.TAG !== "Module") {
6664
return;
65+
}
66+
let comps = shape._0;
67+
for (let i$1 = 0, i_finish = comps.length; i$1 < i_finish; ++i$1) {
68+
let match = comps[i$1];
69+
let name = match[1];
70+
aux(match[0], o[name], n[name], o, name);
71+
}
72+
return;
6773
}
6874
};
69-
if ("Module") {
75+
if (typeof shape !== "object") {
76+
throw {
77+
RE_EXN_ID: "Assert_failure",
78+
_1: [
79+
"Primitive_module.res",
80+
68,
81+
9
82+
],
83+
Error: new Error()
84+
};
85+
}
86+
if (shape.TAG === "Module") {
7087
let comps = shape._0;
7188
for (let i = 0, i_finish = comps.length; i < i_finish; ++i) {
7289
let match = comps[i];

tests/tests/src/VariantPatternMatchingSpreadsWithPayloads.mjs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33

44
function doWithA(a) {
5-
switch (typeof a) {
6-
case "One" :
5+
if (typeof a !== "object") {
6+
if (a === "One") {
77
console.log("aaa");
88
return;
9-
case "Three" :
10-
console.log("threeeee");
11-
return;
12-
case "Two" :
13-
console.log("twwwoooo");
14-
return;
9+
}
10+
console.log("threeeee");
11+
return;
12+
} else {
13+
console.log("twwwoooo");
14+
return;
1515
}
1616
}
1717

1818
function doWithB(b) {
19-
if ("One") {
20-
console.log("aaa");
19+
if (typeof b !== "object") {
20+
if (b === "One") {
21+
console.log("aaa");
22+
return;
23+
}
24+
console.log("twwwoooo");
25+
return;
26+
} else {
27+
console.log("twwwoooo");
2128
return;
2229
}
23-
console.log("twwwoooo");
2430
}
2531

2632
function lookup(b) {
27-
switch (typeof b) {
33+
if (typeof b === "object") {
34+
return doWithA(b);
35+
}
36+
switch (b) {
2837
case "Four" :
2938
console.log("four");
3039
return;
@@ -37,16 +46,23 @@ function lookup(b) {
3746
}
3847

3948
function lookup2(d) {
40-
switch (typeof d) {
41-
case "Four" :
42-
case "Five" :
43-
return doWithB(d);
44-
case "Six" :
45-
case "Seven" :
46-
console.log("Got rest of d");
47-
return;
48-
default:
49+
if (typeof d !== "object") {
50+
switch (d) {
51+
case "Four" :
52+
case "Five" :
53+
return doWithB(d);
54+
case "Six" :
55+
console.log("Got rest of d");
56+
return;
57+
default:
58+
return doWithA(d);
59+
}
60+
} else {
61+
if (d.TAG !== "Seven") {
4962
return doWithA(d);
63+
}
64+
console.log("Got rest of d");
65+
return;
5066
}
5167
}
5268

0 commit comments

Comments
 (0)