瀏覽代碼

allow contravariant arguments and covariant returns (fixed issue #783)

Simon Krajewski 13 年之前
父節點
當前提交
2dd6cfb53a
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      typeload.ml

+ 5 - 3
typeload.ml

@@ -330,7 +330,7 @@ let load_type_opt ?(opt=false) ctx p t =
 
 let valid_redefinition ctx f1 t1 f2 t2 =
 	let valid t1 t2 =
-		type_eq EqStrict t1 t2;
+		unify_raise ctx t1 t2 f2.cf_pos;
 		if is_null t1 <> is_null t2 then raise (Unify_error [Cannot_unify (t1,t2)]);
 	in
 	let t1, t2 = (match f1.cf_params, f2.cf_params with
@@ -344,12 +344,14 @@ let valid_redefinition ctx f1 t1 f2 t2 =
 	| TFun (args1,r1) , TFun (args2,r2) when List.length args1 = List.length args2 ->
 		List.iter2 (fun (n,o1,a1) (_,o2,a2) ->
 			if o1 <> o2 then raise (Unify_error [Not_matching_optional n]);
-			valid a1 a2;
+			valid a2 a1;
 		) args1 args2;
+		unify_raise ctx r1 r2 f2.cf_pos;
 		valid r1 r2;
 	| _ , _ ->
 		(* in case args differs, or if an interface var *)
-		valid t1 t2
+		type_eq EqStrict t1 t2;
+		if is_null t1 <> is_null t2 then raise (Unify_error [Cannot_unify (t1,t2)])
 
 let copy_meta meta_src meta_target sl =
 	let meta = ref meta_target in