Skip to content
Prev Previous commit
Next Next commit
add tests for inlined record of pattern matching
  • Loading branch information
mununki committed Nov 20, 2022
commit fee0edac7e77dc363bbd6b6f441be7e9755d0fff
97 changes: 97 additions & 0 deletions jscomp/test/record_regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,96 @@ function setAA(ao) {
};
}

var ir0 = {
TAG: /* V0 */0,
x0: "v0",
x3: 3
};

var ir1 = {
TAG: /* V0 */0,
x0: "v0",
x1: "v1",
x3: 3
};

var ir2 = {
TAG: /* V0 */0,
x0: "v0",
x1: "v1",
x2: 2,
x3: 3
};

var pm0;

pm0 = ir0.TAG === /* V0 */0 ? [
"v0",
3
] : [
"v0",
undefined
];

var pm1;

pm1 = ir1.TAG === /* V0 */0 ? [
"v0",
"v1",
3
] : [
"v0",
undefined,
"v1"
];

var pm2;

pm2 = ir2.TAG === /* V0 */0 ? [
"v0",
"v1",
2,
3
] : [
"v0",
undefined,
undefined,
"v1"
];

var pm3;

if (ir2.TAG === /* V0 */0) {
var x2 = 2;
var x1 = "v1";
var x0 = "v0";
pm3 = Caml_obj.equal(x1, "x1") ? [
x0,
"x1!",
x2,
3
] : (
x1 !== undefined ? [
x0,
x1,
x2,
3
] : [
x0,
"not existed",
x2,
3
]
);
} else {
pm3 = [
"v0",
"not existed",
undefined,
"v1"
];
}

var f2 = {
x: 3,
y: 3,
Expand Down Expand Up @@ -104,4 +194,11 @@ exports.po = po;
exports.setAA = setAA;
exports.foo1 = foo1;
exports.foo2 = foo2;
exports.ir0 = ir0;
exports.ir1 = ir1;
exports.ir2 = ir2;
exports.pm0 = pm0;
exports.pm1 = pm1;
exports.pm2 = pm2;
exports.pm3 = pm3;
/* Not a pure module */
27 changes: 27 additions & 0 deletions jscomp/test/record_regression.res
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,30 @@ let foo2 = Foo({name: "foo", age: 3})
// should be type error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed 651ba2b

// let foo3 = Foo({name: "foo", age: 3, nickname: "hasNoNickname"})
// let foo4 = Foo({name: "foo", age: "3"})

type inlinedRecord = V0({x0: string, x1?: string, x2?: int, x3: int}) | V1({y0: string, y1: int})

let ir0 = V0({x0: "v0", x3: 3})
let ir1 = V0({x0: "v0", x1: "v1", x3: 3})
let ir2 = V0({x0: "v0", x1: "v1", x2: 2, x3: 3})

let pm0 = switch ir0 {
| V0({x0, x3}) => (x0, x3)
| V1({y0, y1}) => (y0, y1)
}
let pm1 = switch ir1 {
| V0({x0, x1, x3}) => (x0, x1, x3)
| V1({y0, y1}) => (y0, None, y1)
}
let pm2 = switch ir2 {
| V0({x0, x1, x2, x3}) => (x0, x1, x2, x3)
| V1({y0, y1}) => (y0, None, None, y1)
}
let pm3 = switch ir2 {
| V0({x0, x1, x2, x3}) if x1 == Some("x1") => (x0, "x1!", x2, x3)
| V0({x0, x1, x2, x3}) => switch x1 {
| Some(x1) => (x0, x1, x2, x3)
| None => (x0, "not existed", x2, x3)
}
| V1({y0, y1}) => (y0, "not existed", None, y1)
}