Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jscomp/test/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ build test/module_as_function.cmi test/module_as_function.cmj : cc test/module_a
build test/module_missing_conversion.cmi test/module_missing_conversion.cmj : cc test/module_missing_conversion.ml | $stdlib
build test/module_parameter_test.cmi test/module_parameter_test.cmj : cc test/module_parameter_test.ml | test/mt.cmj $stdlib
build test/module_splice_test.cmi test/module_splice_test.cmj : cc test/module_splice_test.ml | test/mt.cmj $stdlib
build test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj : cc test/more_poly_variant_test.ml | $stdlib
build test/more_uncurry.cmi test/more_uncurry.cmj : cc test/more_uncurry.ml | $stdlib
build test/mpr_6033_test.cmi test/mpr_6033_test.cmj : cc test/mpr_6033_test.ml | test/mt.cmj $stdlib
build test/mt.cmj : cc_cmi test/mt.ml | test/mt.cmi $stdlib
Expand Down
91 changes: 91 additions & 0 deletions jscomp/test/more_poly_variant_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';


function map(f, param) {
if (typeof param === "number") {
return /* Nil */3902385;
}
var match = param.VAL;
return {
HASH: /* Cons */748545553,
VAL: [
f(match[0]),
map(f, match[1])
]
};
}

function split_cases(x) {
if (typeof x === "number" || x.HASH < 925929103) {
return {
HASH: /* A */65,
VAL: x
};
} else {
return {
HASH: /* B */66,
VAL: x
};
}
}

function f(param) {
if (typeof param === "number") {
return "Tag3";
} else {
return "myvariant";
}
}

function g1(param) {
if (param.HASH >= 936370360) {
return "Tag2";
} else {
return "Tag1";
}
}

function g(x) {
if (typeof x === "number") {
return "Tag3";
} else {
return g1(x);
}
}

function f1(param) {
if (param >= 14610) {
return "A";
} else {
return "other";
}
}

function f2(x) {
if (typeof x === "number") {
if (x >= 616641298) {
if (x >= 936370362) {
console.log(x);
return 2;
} else {
return 3;
}
} else if (x >= 104) {
return 2;
} else {
return 333;
}
} else {
console.log(x);
return 2;
}
}

exports.map = map;
exports.split_cases = split_cases;
exports.f = f;
exports.g1 = g1;
exports.g = g;
exports.f1 = f1;
exports.f2 = f2;
/* No side effect */
42 changes: 42 additions & 0 deletions jscomp/test/more_poly_variant_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
type 'a vlist = [`Nil | `Cons of 'a * 'a vlist];;

let rec map f : 'a vlist -> 'b vlist = function
| `Nil -> `Nil
| `Cons(a, l) -> `Cons(f a [@bs], map f l)
;;


let split_cases = function
| `Nil | `Cons _ as x -> `A x
| `Snoc _ as x -> `B x
;;


type myvariant = [`Tag1 of int | `Tag2 of bool]


let f = function
| #myvariant -> "myvariant"
| `Tag3 -> "Tag3";;

let g1 = function `Tag1 _ -> "Tag1" | `Tag2 _ -> "Tag2";;


let g = function
| #myvariant as x -> g1 x
| `Tag3 -> "Tag3";;

type abc = [`A | `B | `C] ;;

let f1 = function
| `As -> "A"
| #abc -> "other" ;;

type myvariant2 = [`Tag3 of int | `Tag4 | myvariant]
type x = [`a | `b | `c ]
let f2 x =
match x with
| #myvariant2 as x -> Js.log x ; 2
| `hello -> 3
| `h -> 2
| #x -> 333