-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathppx_this_obj_test.ml
62 lines (53 loc) · 1.34 KB
/
ppx_this_obj_test.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc (x, y) =
incr test_id ;
suites :=
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
let v =
let x = 3. in
object (self)
method x () = x
method say x = x *. self## x ()
method hi x y = self##say x +. y
end
(** compile infer
class type js_obj = object
method x : unit -> float
method say : float -> float
method hi : float -> float -> float
end [@bs]
val js_obj : js_obj
*)
let v2 =
let x = 3. in
object (self)
method hi x = fun y -> self##say x +. y
method say = fun x -> x *. self## x ()
method x () = x
end
let v3 =
let x = 3. in
object (self)
method hi x y =
let u = [%bs.obj{ x }] in
self##say u##x +. y +.x
method say = fun x -> x *. self## x ()
method x () = x
end
let v4 =
object
method hi x y = x +. y
method say x = x
method x () = 1.
end
(* let v5 = *)
(* object *)
(* method x = x *)
(* end [@bs] *)
(** guarantee they have the same type *)
let collection = [| v ; v2 ; v3 ; v4 |]
let () =
eq __LOC__ (11., v##hi 3. 2.);
eq __LOC__ (11., v2##hi 3. 2.)
let () = Mt.from_pair_suites __MODULE__ !suites