Pārlūkot izejas kodu

added tip for type parameter invariance in unify errors

Nicolas Cannasse 13 gadi atpakaļ
vecāks
revīzija
57925af2dc
2 mainītis faili ar 10 papildinājumiem un 4 dzēšanām
  1. 8 4
      type.ml
  2. 2 0
      typecore.ml

+ 8 - 4
type.ml

@@ -564,6 +564,7 @@ type unify_error =
 	| Invalid_visibility of string
 	| Not_matching_optional of string
 	| Cant_force_optional
+	| Invariant_parameter of t * t
 
 exception Unify_error of unify_error list
 
@@ -901,10 +902,13 @@ let rec unify a b =
 		error [cannot_unify a b]
 
 and unify_types a b tl1 tl2 =
-	try
-		List.iter2 (type_eq EqRightDynamic) tl1 tl2
-	with
-		Unify_error l -> error ((cannot_unify a b) :: l)
+	List.iter2 (fun t1 t2 ->
+		try
+			type_eq EqRightDynamic t1 t2 
+		with Unify_error l ->
+			let err = cannot_unify a b in
+			error (try unify t1 t2; (err :: (Invariant_parameter (t1,t2)) :: l) with _ -> err :: l)
+	) tl1 tl2
 
 and unify_with_access t1 f2 =
 	match f2.cf_kind with

+ 2 - 0
typecore.ml

@@ -127,6 +127,8 @@ let unify_error_msg ctx = function
 		"Optional attribute of parameter " ^ n ^ " differs"
 	| Cant_force_optional ->
 		"Optional parameters can't be forced"
+	| Invariant_parameter _ ->
+		"Type parameters are invariant"
 
 let rec error_msg = function
 	| Module_not_found m -> "Class not found : " ^ Ast.s_type_path m