瀏覽代碼

allowed class instance :> anonymous subtyping.

Nicolas Cannasse 20 年之前
父節點
當前提交
60e0554ccb
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      type.ml

+ 9 - 0
type.ml

@@ -309,6 +309,15 @@ let rec unify a b =
 		loop c1 tl1
 	| TFun (l1,r1) , TFun (l2,r2) when List.length l1 = List.length l2 ->
 		unify r1 r2 && List.for_all2 unify l2 l1 (* contravariance *)
+	| TInst (c,tl) , TAnon fl ->
+		(try
+			PMap.iter (fun n f2 ->
+				let f1 = PMap.find n c.cl_fields in				
+				if not (unify (apply_params c.cl_types tl f1.cf_type) f2.cf_type) then raise Not_found;
+			) fl;
+			true
+		with
+			Not_found -> false)
 	| TAnon fl1 , TAnon fl2 ->
 		(try
 			PMap.iter (fun n f2 ->