Bläddra i källkod

[typer] start on improved error messages

Simon Krajewski 7 år sedan
förälder
incheckning
25f1d5b264
2 ändrade filer med 8 tillägg och 3 borttagningar
  1. 4 0
      src/core/error.ml
  2. 4 3
      src/core/type.ml

+ 4 - 0
src/core/error.ml

@@ -68,6 +68,10 @@ let unify_error_msg ctx = function
 		cf.cf_name ^ " has no overload for " ^ s_type ctx t
 		cf.cf_name ^ " has no overload for " ^ s_type ctx t
 	| FinalInvariance ->
 	| FinalInvariance ->
 		"Cannot unify final and non-final fields"
 		"Cannot unify final and non-final fields"
+	| Invalid_function_argument i ->
+		Printf.sprintf "Cannot unify argument %i" i
+	| Invalid_return_type ->
+		"Cannot unify return types"
 	| Unify_custom msg ->
 	| Unify_custom msg ->
 		msg
 		msg
 
 

+ 4 - 3
src/core/type.ml

@@ -51,7 +51,6 @@ type module_check_policy =
 	| NoCheckDependencies
 	| NoCheckDependencies
 	| NoCheckShadowing
 	| NoCheckShadowing
 
 
-
 type t =
 type t =
 	| TMono of t option ref
 	| TMono of t option ref
 	| TEnum of tenum * tparams
 	| TEnum of tenum * tparams
@@ -1702,6 +1701,8 @@ type unify_error =
 	| Constraint_failure of string
 	| Constraint_failure of string
 	| Missing_overload of tclass_field * t
 	| Missing_overload of tclass_field * t
 	| FinalInvariance (* nice band name *)
 	| FinalInvariance (* nice band name *)
+	| Invalid_function_argument of int
+	| Invalid_return_type
 	| Unify_custom of string
 	| Unify_custom of string
 
 
 exception Unify_error of unify_error list
 exception Unify_error of unify_error list
@@ -2010,8 +2011,8 @@ let rec unify a b =
 			) l2 l1 (* contravariance *)
 			) l2 l1 (* contravariance *)
 		with
 		with
 			Unify_error l ->
 			Unify_error l ->
-				let msg = if !i = 0 then "Cannot unify return types" else "Cannot unify argument " ^ (string_of_int !i) in
-				error (cannot_unify a b :: Unify_custom msg :: l))
+				let msg = if !i = 0 then Invalid_return_type else Invalid_function_argument !i in
+				error (cannot_unify a b :: msg :: l))
 	| TInst (c,tl) , TAnon an ->
 	| TInst (c,tl) , TAnon an ->
 		if PMap.is_empty an.a_fields then (match c.cl_kind with
 		if PMap.is_empty an.a_fields then (match c.cl_kind with
 			| KTypeParameter pl ->
 			| KTypeParameter pl ->