瀏覽代碼

fixed rest args typing for overloaded functions (closes #10143)

Aleksandr Kuzmenko 4 年之前
父節點
當前提交
9f730082b8
共有 3 個文件被更改,包括 33 次插入8 次删除
  1. 1 4
      src/filters/exceptions.ml
  2. 11 4
      src/typing/callUnification.ml
  3. 21 0
      tests/unit/src/unit/issues/Issue10143.hx

+ 1 - 4
src/filters/exceptions.ml

@@ -109,10 +109,7 @@ let rec is_native_throw cfg t =
 	Check if `t` can be caught without wrapping.
 *)
 let rec is_native_catch ctx t =
-	if ctx.typer.com.platform = Eval then
-		true
-	else
-		is_in_list t ctx.config.ec_native_catches
+	ctx.typer.com.platform = Eval || is_in_list t ctx.config.ec_native_catches
 
 (**
 	Check if `cls` is or extends (if `check_parent=true`) `haxe.Exception`

+ 11 - 4
src/typing/callUnification.ml

@@ -80,13 +80,18 @@ let rec unify_call_args ctx el args r callp inline force_inline in_overload =
 		skipped := (name,ul,p) :: !skipped;
 		default_value name t
 	in
+	let handle_errors fn =
+		try
+			fn()
+		with Error(l,p) when (match l with Call_error _ | Module_not_found _ -> false | _ -> true) ->
+			raise (WithTypeError (l,p))
+	in
 	(* let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, (has_class_flag c CExtern) | _ -> false, false in *)
 	let type_against name t e =
-		try
+		handle_errors (fun() ->
 			let e = type_expr ctx e (WithType.with_argument t name) in
 			!cast_or_unify_raise_ref ctx t e e.epos
-		with Error(l,p) when (match l with Call_error _ | Module_not_found _ -> false | _ -> true) ->
-			raise (WithTypeError (l,p))
+		)
 	in
 	let rec loop el args = match el,args with
 		| [],[] ->
@@ -124,7 +129,9 @@ let rec unify_call_args ctx el args r callp inline force_inline in_overload =
 									Type.unify arg_t (unify_min ctx el);
 									el
 								with Unify_error _ ->
-									die ~p:callp "Unexpected unification error" __LOC__
+									handle_errors (fun() ->
+										List.map (fun e -> !cast_or_unify_raise_ref ctx arg_t e e.epos) el
+									)
 							with WithTypeError(ul,p) ->
 								arg_error ul name false p)
 						| _ ->

+ 21 - 0
tests/unit/src/unit/issues/Issue10143.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+//targets with pf_supports_rest_args = true
+#if (js || lua || php || cs || java || python || flash)
+
+class Issue10143 extends Test {
+	function test1() {
+		noAssert();
+		eq('String', HelperMacros.typeString(Win.test('hello')));
+		eq('Bool', HelperMacros.typeString(Win.test({field:'world'})));
+	}
+}
+
+private extern class Win {
+	overload static function test<T:{field:String}>(items:...T):Bool;
+	overload static function test(items:...String):String;
+}
+
+#else
+class Issue10143 extends Test {}
+#end