Skip to content

Commit c4abe7c

Browse files
committed
add tests for inlined record of pattern matching
1 parent a8abd47 commit c4abe7c

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

jscomp/test/record_regression.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,96 @@ function setAA(ao) {
6060
};
6161
}
6262

63+
var ir0 = {
64+
TAG: /* V0 */0,
65+
x0: "v0",
66+
x3: 3
67+
};
68+
69+
var ir1 = {
70+
TAG: /* V0 */0,
71+
x0: "v0",
72+
x1: "v1",
73+
x3: 3
74+
};
75+
76+
var ir2 = {
77+
TAG: /* V0 */0,
78+
x0: "v0",
79+
x1: "v1",
80+
x2: 2,
81+
x3: 3
82+
};
83+
84+
var pm0;
85+
86+
pm0 = ir0.TAG === /* V0 */0 ? [
87+
"v0",
88+
3
89+
] : [
90+
"v0",
91+
undefined
92+
];
93+
94+
var pm1;
95+
96+
pm1 = ir1.TAG === /* V0 */0 ? [
97+
"v0",
98+
"v1",
99+
3
100+
] : [
101+
"v0",
102+
undefined,
103+
"v1"
104+
];
105+
106+
var pm2;
107+
108+
pm2 = ir2.TAG === /* V0 */0 ? [
109+
"v0",
110+
"v1",
111+
2,
112+
3
113+
] : [
114+
"v0",
115+
undefined,
116+
undefined,
117+
"v1"
118+
];
119+
120+
var pm3;
121+
122+
if (ir2.TAG === /* V0 */0) {
123+
var x2 = 2;
124+
var x1 = "v1";
125+
var x0 = "v0";
126+
pm3 = Caml_obj.equal(x1, "x1") ? [
127+
x0,
128+
"x1!",
129+
x2,
130+
3
131+
] : (
132+
x1 !== undefined ? [
133+
x0,
134+
x1,
135+
x2,
136+
3
137+
] : [
138+
x0,
139+
"not existed",
140+
x2,
141+
3
142+
]
143+
);
144+
} else {
145+
pm3 = [
146+
"v0",
147+
"not existed",
148+
undefined,
149+
"v1"
150+
];
151+
}
152+
63153
var f2 = {
64154
x: 3,
65155
y: 3,
@@ -104,4 +194,11 @@ exports.po = po;
104194
exports.setAA = setAA;
105195
exports.foo1 = foo1;
106196
exports.foo2 = foo2;
197+
exports.ir0 = ir0;
198+
exports.ir1 = ir1;
199+
exports.ir2 = ir2;
200+
exports.pm0 = pm0;
201+
exports.pm1 = pm1;
202+
exports.pm2 = pm2;
203+
exports.pm3 = pm3;
107204
/* Not a pure module */

jscomp/test/record_regression.res

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,30 @@ let foo2 = Foo({name: "foo", age: 3})
109109
// should be type error
110110
// let foo3 = Foo({name: "foo", age: 3, nickname: "hasNoNickname"})
111111
// let foo4 = Foo({name: "foo", age: "3"})
112+
113+
type inlinedRecord = V0({x0: string, x1?: string, x2?: int, x3: int}) | V1({y0: string, y1: int})
114+
115+
let ir0 = V0({x0: "v0", x3: 3})
116+
let ir1 = V0({x0: "v0", x1: "v1", x3: 3})
117+
let ir2 = V0({x0: "v0", x1: "v1", x2: 2, x3: 3})
118+
119+
let pm0 = switch ir0 {
120+
| V0({x0, x3}) => (x0, x3)
121+
| V1({y0, y1}) => (y0, y1)
122+
}
123+
let pm1 = switch ir1 {
124+
| V0({x0, x1, x3}) => (x0, x1, x3)
125+
| V1({y0, y1}) => (y0, None, y1)
126+
}
127+
let pm2 = switch ir2 {
128+
| V0({x0, x1, x2, x3}) => (x0, x1, x2, x3)
129+
| V1({y0, y1}) => (y0, None, None, y1)
130+
}
131+
let pm3 = switch ir2 {
132+
| V0({x0, x1, x2, x3}) if x1 == Some("x1") => (x0, "x1!", x2, x3)
133+
| V0({x0, x1, x2, x3}) => switch x1 {
134+
| Some(x1) => (x0, x1, x2, x3)
135+
| None => (x0, "not existed", x2, x3)
136+
}
137+
| V1({y0, y1}) => (y0, "not existed", None, y1)
138+
}

0 commit comments

Comments
 (0)