Skip to content

Commit 9aa849e

Browse files
committed
Add example of constructor tag repoted as Unknown.
This happens together with warning: ``` Warning 40: Pdot was selected from type Path.t. It is not visible in the current scope, and will not be selected if the type becomes unknown. ```
1 parent d0bb845 commit 9aa849e

File tree

2 files changed

+89
-29
lines changed

2 files changed

+89
-29
lines changed

jscomp/test/variant.js

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
'use strict';
22

33
var Block = require("../../lib/js/block.js");
4-
5-
var b = /* B */Block.__(0, [34]);
6-
7-
var c = /* C */Block.__(1, [
8-
4,
9-
2
10-
]);
11-
12-
var d = /* D */Block.__(2, [/* tuple */[
13-
4,
14-
2
15-
]]);
16-
17-
console.log("a1", /* A1 */0);
18-
19-
console.log("a2", /* A2 */1);
20-
21-
console.log("b", b);
22-
23-
console.log("c", c);
24-
25-
console.log("d", d);
4+
var Caml_obj = require("../../lib/js/caml_obj.js");
5+
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
266

277
function foo(param) {
288
if (typeof param === "number") {
@@ -74,10 +54,68 @@ function switchNum(param) {
7454
}
7555
}
7656

57+
var same = Caml_obj.caml_equal;
58+
59+
var compare = Caml_obj.caml_compare;
60+
61+
var Path = {
62+
same: same,
63+
compare: compare
64+
};
65+
66+
function Make(M) {
67+
var find = function (x) {
68+
return /* () */0;
69+
};
70+
return {
71+
find: find
72+
};
73+
}
74+
75+
function find(x) {
76+
return /* () */0;
77+
}
78+
79+
var M = {
80+
find: find
81+
};
82+
83+
function rollback_path(subst, p) {
84+
try {
85+
return "try";
86+
}
87+
catch (exn){
88+
if (exn === Caml_builtin_exceptions.not_found) {
89+
switch (p.tag | 0) {
90+
case /* Unknown */1 :
91+
return "Pdot";
92+
case /* Unknown */0 :
93+
case /* Unknown */2 :
94+
return "Pident | Papply";
95+
96+
}
97+
} else {
98+
throw exn;
99+
}
100+
}
101+
}
102+
77103
var a1 = /* A1 */0;
78104

79105
var a2 = /* A2 */1;
80106

107+
var b = /* B */Block.__(0, [34]);
108+
109+
var c = /* C */Block.__(1, [
110+
4,
111+
2
112+
]);
113+
114+
var d = /* D */Block.__(2, [/* tuple */[
115+
4,
116+
2
117+
]]);
118+
81119
exports.a1 = a1;
82120
exports.a2 = a2;
83121
exports.b = b;
@@ -87,4 +125,8 @@ exports.foo = foo;
87125
exports.fooA1 = fooA1;
88126
exports.fooC = fooC;
89127
exports.switchNum = switchNum;
90-
/* Not a pure module */
128+
exports.Path = Path;
129+
exports.Make = Make;
130+
exports.M = M;
131+
exports.rollback_path = rollback_path;
132+
/* No side effect */

jscomp/test/variant.ml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ let c = C (4,2)
1111

1212
let d = D (4,2)
1313

14-
let () = Js.log2 "a1" a1
15-
let () = Js.log2 "a2" a2
16-
let () = Js.log2 "b" b
17-
let () = Js.log2 "c" c
18-
let () = Js.log2 "d" d
19-
2014
let foo = function
2115
| A1 -> 1
2216
| A2 -> 2
@@ -37,3 +31,27 @@ let switchNum = function
3731
| 1 -> "1"
3832
| 2 -> "2"
3933
| _ -> "_"
34+
35+
module Path = struct
36+
type t =
37+
Pident of string
38+
| Pdot of t * string * int
39+
| Papply of t * t
40+
let same = (=)
41+
let compare = compare
42+
end
43+
44+
module Make(M : sig type t = Path.t end) = struct
45+
type t = M.t
46+
let find (x:t) = ()
47+
end
48+
49+
module M = Make(Path)
50+
51+
let rollback_path subst p =
52+
let _ = M.find p in
53+
try "try"
54+
with Not_found ->
55+
match p with
56+
Pident _ | Papply _ -> "Pident | Papply"
57+
| Pdot _ -> "Pdot"

0 commit comments

Comments
 (0)