Skip to content

Commit 8cdd666

Browse files
committed
add two edge case for ocaml classes
1 parent d08373a commit 8cdd666

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ build test/ocaml_typedtree_test.cmi : cc test/ocaml_typedtree_test.mli | $stdlib
471471
build test/of_string_test.cmi test/of_string_test.cmj : cc test/of_string_test.ml | test/mt.cmj $stdlib
472472
build test/offset.cmi test/offset.cmj : cc test/offset.ml | $stdlib
473473
build test/oo_js_test_date.cmi test/oo_js_test_date.cmj : cc test/oo_js_test_date.ml | test/mt.cmj $stdlib
474+
build test/opr_3576_test.cmi test/opr_3576_test.cmj : cc test/opr_3576_test.ml | test/mt.cmj $stdlib
475+
build test/opr_4560_test.cmi test/opr_4560_test.cmj : cc test/opr_4560_test.ml | test/mt.cmj $stdlib
474476
build test/option_repr_test.cmi test/option_repr_test.cmj : cc test/option_repr_test.ml | test/mt.cmj $stdlib
475477
build test/optional_ffi_test.cmi test/optional_ffi_test.cmj : cc test/optional_ffi_test.ml | test/mt.cmj $stdlib
476478
build test/optional_regression_test.cmi test/optional_regression_test.cmj : cc test/optional_regression_test.ml | test/mt.cmj $stdlib

jscomp/test/opr_3576_test.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
var Curry = require("../../lib/js/curry.js");
5+
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");
6+
var CamlinternalOO = require("../../lib/js/camlinternalOO.js");
7+
8+
var shared = [
9+
"m1",
10+
"m2"
11+
];
12+
13+
var suites = {
14+
contents: /* [] */0
15+
};
16+
17+
var test_id = {
18+
contents: 0
19+
};
20+
21+
function eq(loc, x, y) {
22+
return Mt.eq_suites(test_id, suites, loc, x, y);
23+
}
24+
25+
var class_tables = /* Cons */[
26+
/* key */undefined,
27+
/* data */undefined,
28+
/* next */undefined
29+
];
30+
31+
var class_tables$1 = /* Cons */[
32+
/* key */undefined,
33+
/* data */undefined,
34+
/* next */undefined
35+
];
36+
37+
function a_init($$class) {
38+
var ids = CamlinternalOO.get_method_labels($$class, [
39+
"m2",
40+
"m1"
41+
]);
42+
var m2 = ids[0];
43+
var m1 = ids[1];
44+
CamlinternalOO.set_methods($$class, [
45+
m1,
46+
(function (self$1) {
47+
if (!class_tables$1[/* key */0]) {
48+
var $$class = CamlinternalOO.create_table(["m3"]);
49+
var env = CamlinternalOO.new_variable($$class, "");
50+
var m3 = CamlinternalOO.get_method_label($$class, "m3");
51+
CamlinternalOO.set_method($$class, m3, (function (self$2) {
52+
return 3;
53+
}));
54+
var env_init = function (env$1) {
55+
var self = CamlinternalOO.create_object_opt(undefined, $$class);
56+
self[env] = env$1;
57+
return self;
58+
};
59+
CamlinternalOO.init_class($$class);
60+
class_tables$1[/* key */0] = env_init;
61+
}
62+
return Curry._1(class_tables$1[/* key */0], undefined);
63+
}),
64+
m2,
65+
(function (self$1) {
66+
if (!class_tables[/* key */0]) {
67+
var $$class = CamlinternalOO.create_table(["m4"]);
68+
var env = CamlinternalOO.new_variable($$class, "");
69+
var m4 = CamlinternalOO.get_method_label($$class, "m4");
70+
CamlinternalOO.set_method($$class, m4, (function (self$3) {
71+
var env$1 = self$3[env];
72+
var tmp = env$1[1];
73+
return Curry._1(tmp[0][env$1[0]], tmp);
74+
}));
75+
var env_init = function (env$1) {
76+
var self = CamlinternalOO.create_object_opt(undefined, $$class);
77+
self[env] = env$1;
78+
return self;
79+
};
80+
CamlinternalOO.init_class($$class);
81+
class_tables[/* key */0] = env_init;
82+
}
83+
return Curry._1(class_tables[/* key */0], [
84+
m1,
85+
self$1
86+
]);
87+
})
88+
]);
89+
return function (env, self) {
90+
return CamlinternalOO.create_object_opt(self, $$class);
91+
};
92+
}
93+
94+
var a = CamlinternalOO.make_class(shared, a_init);
95+
96+
function b_init($$class) {
97+
var a_text = CamlinternalOO.get_method_label($$class, "a_text");
98+
var inh = CamlinternalOO.inherits($$class, 0, 0, shared, a, true);
99+
var obj_init = inh[0];
100+
CamlinternalOO.set_method($$class, a_text, (function (self$4, param) {
101+
102+
}));
103+
return function (env, self) {
104+
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
105+
Curry._1(obj_init, self$1);
106+
return CamlinternalOO.run_initializers_opt(self, self$1, $$class);
107+
};
108+
}
109+
110+
var b = CamlinternalOO.make_class([
111+
"a_text",
112+
"m1",
113+
"m2"
114+
], b_init);
115+
116+
var tmp = Curry._1(a[0], undefined);
117+
118+
Caml_oo_curry.js1(24357, 1, tmp);
119+
120+
var tmp$1 = Curry._1(b[0], undefined);
121+
122+
var tmp$2 = Caml_oo_curry.js1(24357, 2, tmp$1);
123+
124+
var tmp$3 = Caml_oo_curry.js1(24359, 3, tmp$2);
125+
126+
eq("File \"opr_3576_test.ml\", line 22, characters 6-13", Caml_oo_curry.js1(24358, 4, tmp$3), 3);
127+
128+
Mt.from_pair_suites("opr_3576_test.ml", suites.contents);
129+
130+
exports.suites = suites;
131+
exports.test_id = test_id;
132+
exports.eq = eq;
133+
exports.a = a;
134+
exports.b = b;
135+
/* a Not a pure module */

jscomp/test/opr_3576_test.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
4+
5+
6+
class a =
7+
object (self)
8+
method m1 = object method m3 = 3 end
9+
method m2 =
10+
object
11+
method m4 = self#m1
12+
end
13+
end
14+
15+
class b =
16+
object (self)
17+
inherit a
18+
method a_text () = ()
19+
end
20+
21+
let _ = (new a)#m2
22+
;; eq __LOC__ ((new b)#m2#m4#m3) 3
23+
24+
;; Mt.from_pair_suites __FILE__ !suites

jscomp/test/opr_4560_test.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
var Curry = require("../../lib/js/curry.js");
5+
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");
6+
var CamlinternalOO = require("../../lib/js/camlinternalOO.js");
7+
8+
var shared = ["b"];
9+
10+
var suites = {
11+
contents: /* [] */0
12+
};
13+
14+
var test_id = {
15+
contents: 0
16+
};
17+
18+
function eq(loc, x, y) {
19+
return Mt.eq_suites(test_id, suites, loc, x, y);
20+
}
21+
22+
var class_tables = /* Cons */[
23+
/* key */undefined,
24+
/* data */undefined,
25+
/* next */undefined
26+
];
27+
28+
var class_tables$1 = /* Cons */[
29+
/* key */undefined,
30+
/* data */undefined,
31+
/* next */undefined
32+
];
33+
34+
function c1_init($$class) {
35+
var b = CamlinternalOO.get_method_label($$class, "b");
36+
CamlinternalOO.set_method($$class, b, (function (self$1) {
37+
if (!class_tables[/* key */0]) {
38+
var $$class = CamlinternalOO.create_table([
39+
"c",
40+
"h"
41+
]);
42+
var env = CamlinternalOO.new_variable($$class, "");
43+
var ids = CamlinternalOO.get_method_labels($$class, [
44+
"h",
45+
"c"
46+
]);
47+
var h = ids[0];
48+
var c = ids[1];
49+
CamlinternalOO.set_methods($$class, [
50+
c,
51+
(function (self$2) {
52+
var env$1 = self$2[env];
53+
if (!class_tables$1[/* key */0]) {
54+
var $$class = CamlinternalOO.create_table(["d"]);
55+
var env$2 = CamlinternalOO.new_variable($$class, "");
56+
var d = CamlinternalOO.get_method_label($$class, "d");
57+
CamlinternalOO.set_method($$class, d, (function (self$3) {
58+
var env$3 = self$3[env$2];
59+
var tmp = env$3[1];
60+
return Curry._1(tmp[0][env$3[0]], tmp);
61+
}));
62+
var env_init = function (env$3) {
63+
var self = CamlinternalOO.create_object_opt(undefined, $$class);
64+
self[env$2] = env$3;
65+
return self;
66+
};
67+
CamlinternalOO.init_class($$class);
68+
class_tables$1[/* key */0] = env_init;
69+
}
70+
return Curry._1(class_tables$1[/* key */0], [
71+
env$1[0],
72+
env$1[1]
73+
]);
74+
}),
75+
h,
76+
(function (self$2) {
77+
return 33;
78+
})
79+
]);
80+
var env_init = function (env$1) {
81+
var self = CamlinternalOO.create_object_opt(undefined, $$class);
82+
self[env] = env$1;
83+
return self;
84+
};
85+
CamlinternalOO.init_class($$class);
86+
class_tables[/* key */0] = env_init;
87+
}
88+
return Curry._1(class_tables[/* key */0], [
89+
b,
90+
self$1
91+
]);
92+
}));
93+
return function (env, self) {
94+
return CamlinternalOO.create_object_opt(self, $$class);
95+
};
96+
}
97+
98+
var c1 = CamlinternalOO.make_class(shared, c1_init);
99+
100+
function c2_init($$class) {
101+
var a = CamlinternalOO.get_method_label($$class, "a");
102+
var inh = CamlinternalOO.inherits($$class, 0, 0, shared, c1, true);
103+
var obj_init = inh[0];
104+
CamlinternalOO.set_method($$class, a, (function (self$4) {
105+
106+
}));
107+
return function (env, self) {
108+
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
109+
Curry._1(obj_init, self$1);
110+
return CamlinternalOO.run_initializers_opt(self, self$1, $$class);
111+
};
112+
}
113+
114+
var c2 = CamlinternalOO.make_class([
115+
"a",
116+
"b"
117+
], c2_init);
118+
119+
var tmp = Curry._1(c2[0], undefined);
120+
121+
Caml_oo_curry.js1(98, 1, tmp);
122+
123+
var tmp$1 = Curry._1(c1[0], undefined);
124+
125+
var tmp$2 = Caml_oo_curry.js1(98, 2, tmp$1);
126+
127+
var tmp$3 = Caml_oo_curry.js1(99, 3, tmp$2);
128+
129+
var tmp$4 = Caml_oo_curry.js1(100, 4, tmp$3);
130+
131+
var e = Caml_oo_curry.js1(104, 5, tmp$4);
132+
133+
eq("File \"opr_4560_test.ml\", line 26, characters 3-10", e, 33);
134+
135+
Mt.from_pair_suites("opr_4560_test.ml", suites.contents);
136+
137+
var magic = 33;
138+
139+
exports.suites = suites;
140+
exports.test_id = test_id;
141+
exports.eq = eq;
142+
exports.magic = magic;
143+
exports.c1 = c1;
144+
exports.c2 = c2;
145+
exports.e = e;
146+
/* c1 Not a pure module */

jscomp/test/opr_4560_test.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
let magic = 33
6+
class c1 =
7+
object (self)
8+
method b =
9+
object
10+
method c =
11+
object
12+
method d = self # b
13+
end
14+
method h = magic
15+
end
16+
end
17+
18+
class c2 =
19+
object
20+
inherit c1
21+
method a = ()
22+
end
23+
24+
let _ = new c2 # b
25+
let e = new c1 # b # c # d # h ;;
26+
eq __LOC__ e magic
27+
28+
;; Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)