Browse Source

recover from most Error variants when skipping arguments (closes #5321)

Simon Krajewski 9 years ago
parent
commit
47ef5635f2

+ 3 - 3
src/typing/typecore.ml

@@ -142,7 +142,7 @@ exception Forbid_package of (string * path * pos) * pos list * string
 
 
 exception Error of error_msg * pos
 exception Error of error_msg * pos
 
 
-exception WithTypeError of unify_error list * pos
+exception WithTypeError of error_msg * pos
 
 
 let make_call_ref : (typer -> texpr -> texpr list -> t -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> assert false)
 let make_call_ref : (typer -> texpr -> texpr list -> t -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> assert false)
 let type_expr_ref : (typer -> Ast.expr -> with_type -> texpr) ref = ref (fun _ _ _ -> assert false)
 let type_expr_ref : (typer -> Ast.expr -> with_type -> texpr) ref = ref (fun _ _ _ -> assert false)
@@ -261,11 +261,11 @@ let make_static_call ctx c cf map args t p =
 
 
 let raise_or_display ctx l p =
 let raise_or_display ctx l p =
 	if ctx.untyped then ()
 	if ctx.untyped then ()
-	else if ctx.in_call_args then raise (WithTypeError(l,p))
+	else if ctx.in_call_args then raise (WithTypeError(Unify l,p))
 	else display_error ctx (error_msg (Unify l)) p
 	else display_error ctx (error_msg (Unify l)) p
 
 
 let raise_or_display_message ctx msg p =
 let raise_or_display_message ctx msg p =
-	if ctx.in_call_args then raise (WithTypeError ([Unify_custom msg],p))
+	if ctx.in_call_args then raise (WithTypeError (Custom msg,p))
 	else display_error ctx msg p
 	else display_error ctx msg p
 
 
 let unify ctx t1 t2 p =
 let unify ctx t1 t2 p =

+ 9 - 6
src/typing/typer.ml

@@ -678,7 +678,7 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 		raise (Error (Call_error err,p))
 		raise (Error (Call_error err,p))
 	in
 	in
 	let arg_error ul name opt p =
 	let arg_error ul name opt p =
-		let err = Stack (Unify ul,Custom ("For " ^ (if opt then "optional " else "") ^ "function argument '" ^ name ^ "'")) in
+		let err = Stack (ul,Custom ("For " ^ (if opt then "optional " else "") ^ "function argument '" ^ name ^ "'")) in
 		call_error (Could_not_unify err) p
 		call_error (Could_not_unify err) p
 	in
 	in
 	let mk_pos_infos t =
 	let mk_pos_infos t =
@@ -701,8 +701,11 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 	in
 	in
 	(* let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, c.cl_extern | _ -> false, false in *)
 	(* let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, c.cl_extern | _ -> false, false in *)
 	let type_against t e =
 	let type_against t e =
-		let e = type_expr ctx e (WithType t) in
-		(try Codegen.AbstractCast.cast_or_unify_raise ctx t e e.epos with Error (Unify l,p) -> raise (WithTypeError (l,p)))
+		try
+			let e = type_expr ctx e (WithType t) in
+			Codegen.AbstractCast.cast_or_unify_raise ctx t e e.epos
+		with Error(l,p) when (match l with Call_error _ -> false | _ -> true) ->
+			raise (WithTypeError (l,p))
 	in
 	in
 	let rec loop el args = match el,args with
 	let rec loop el args = match el,args with
 		| [],[] ->
 		| [],[] ->
@@ -739,7 +742,7 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 				let e = type_against t e in
 				let e = type_against t e in
 				(e,opt) :: loop el args
 				(e,opt) :: loop el args
 			with
 			with
-				WithTypeError (ul,p) ->
+				WithTypeError (ul,p)->
 					if opt then
 					if opt then
 						let e_def = skip name ul t p in
 						let e_def = skip name ul t p in
 						(e_def,true) :: loop (e :: el) args
 						(e_def,true) :: loop (e :: el) args
@@ -3344,7 +3347,7 @@ and type_map_declaration ctx e1 el with_type p =
 		let unify_min_resume el = try
 		let unify_min_resume el = try
 			unify_min_raise ctx el
 			unify_min_raise ctx el
 		with Error (Unify l,p) when ctx.in_call_args ->
 		with Error (Unify l,p) when ctx.in_call_args ->
-			 raise (WithTypeError(l,p))
+			 raise (WithTypeError(Unify l,p))
 		in
 		in
 		let tkey = unify_min_resume el_k in
 		let tkey = unify_min_resume el_k in
 		let tval = unify_min_resume el_v in
 		let tval = unify_min_resume el_v in
@@ -4608,7 +4611,7 @@ let typing_timer ctx need_type f =
 			Interp.compiler_error (Typecore.error_msg ekind) p
 			Interp.compiler_error (Typecore.error_msg ekind) p
 		| WithTypeError (l,p) ->
 		| WithTypeError (l,p) ->
 			exit();
 			exit();
-			Interp.compiler_error (Typecore.error_msg (Unify l)) p
+			Interp.compiler_error (Typecore.error_msg l) p
 		| e ->
 		| e ->
 			exit();
 			exit();
 			raise e
 			raise e

+ 2 - 1
tests/misc/projects/Issue2148/compile1-fail.hxml.stderr

@@ -1 +1,2 @@
-Main1.hx:7: characters 21-24 : Unknown identifier : foo
+Main1.hx:7: characters 21-24 : Unknown identifier : foo
+Main1.hx:7: characters 21-24 : For function argument 'i'

+ 1 - 0
tests/misc/projects/Issue5321/Chest.hx

@@ -0,0 +1 @@
+class Chest { }

+ 5 - 0
tests/misc/projects/Issue5321/Main.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main(){
+		Test.gt(CHEST);
+	}
+}

+ 16 - 0
tests/misc/projects/Issue5321/Test.hx

@@ -0,0 +1,16 @@
+enum EnumA{
+	EA0;
+	EA1;
+	EA2;
+}
+
+enum EnumB{
+	CHEST;
+	EB0;
+	EB1;
+	EB2;
+}
+
+class Test{
+	public static function gt(?a:EnumA, ?b:EnumB){ }
+}

+ 2 - 0
tests/misc/projects/Issue5321/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 1 - 1
tests/unit/src/unit/issues/Issue3714.hx

@@ -10,6 +10,6 @@ class Issue3714 extends Test {
 		eq(unit.TestType.typeErrorText(A.f), "Cannot access private field f");
 		eq(unit.TestType.typeErrorText(A.f), "Cannot access private field f");
 		eq(unit.TestType.typeErrorText(@:privateAccess A.f), null);
 		eq(unit.TestType.typeErrorText(@:privateAccess A.f), null);
 		eq(unit.TestType.typeErrorText(@:privateAccess A.f(A.a)), null);
 		eq(unit.TestType.typeErrorText(@:privateAccess A.f(A.a)), null);
-		eq(unit.TestType.typeErrorText(@:privateAccess A.f(@:noPrivateAccess A.a)), "Cannot access private field a");
+		eq(unit.TestType.typeErrorText(@:privateAccess A.f(@:noPrivateAccess A.a)), "Cannot access private field a\nFor function argument 'a'");
 	}
 	}
 }
 }