Commits

camlspotter committed 9238382

added mutual recursively defined classes

  • Participants
  • Parent commits 36e2470
  • Branches dev

Comments (0)

Files changed (2)

+module rec M_Object : sig
+  class type s_Object = object
+    method int : int
+    method getIter : M_Iter.s_Iter
+  end
+end = struct
+  class type s_Object = object
+    method int : int
+    method getIter : M_Iter.s_Iter
+  end
+end
+
+and M_Iter : sig
+  class type s_Iter = object
+    inherit M_Object.s_Object
+    method float : float
+    method toObject : M_Object.s_Object
+  end
+end = struct
+  class type s_Iter = object
+    inherit M_Object.s_Object
+    method float : float
+    method toObject : M_Object.s_Object
+  end
+end
+
+open M_Object
+open M_Iter
+
+type t = int
+
+let new_o_Object = ref (fun _ -> assert false)
+let new_o_Iter = ref (fun _ -> assert false)
+
+class o_Object (t : t) : s_Object = object
+  method int = t
+  method getIter = !new_o_Iter t
+end
+
+let _ = new_o_Object := new o_Object
+
+class o_Iter (t : t) : s_Iter = object
+  inherit o_Object t
+  method float = float t
+  method toObject = !new_o_Object t
+end
+
+let _ = new_o_Iter := new o_Iter
+
+let _ = 
+  let o = new o_Object 1 in
+  assert (o#getIter#float = 1.0);
+  assert (o#getIter#toObject#getIter#toObject#int = 1)
+
           in
           begin 
             let init = 
-              let inherits = try Hashtbl.find class_dep_graph tyname with _ -> [] in
+              let _inherits = try Hashtbl.find class_dep_graph tyname with _ -> [] in
               List.fold_left (fun st x ->
                 let ox = "o" ^ x in
                 CrSem(_loc, <:class_str_item< inherit $lid:ox$ >>, st))
-                <:class_str_item< method $tyname$ = (t :> $lid:tyname$ t) >> inherits
+                <:class_str_item< method $tyname$ = (t :> $lid:tyname$ t) >> []
             in
             let methods = List.fold_left (fun st x -> CrSem(_loc, st, x)) init methods in
             let sitem = <:str_item< class $lid:clsname$ t = object $methods$ end >> in