浏览代码

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

Aleksandr Kuzmenko 4 年之前
父节点
当前提交
8572d4b547
共有 3 个文件被更改,包括 33 次插入4 次删除
  1. 1 0
      extra/CHANGES.txt
  2. 11 4
      src/typing/callUnification.ml
  3. 21 0
      tests/unit/src/unit/issues/Issue10143.hx

+ 1 - 0
extra/CHANGES.txt

@@ -2,6 +2,7 @@
 
 	Bugfixes:
 
+	all : fixed rest args typing for overloaded functions (#10143)
 	hl : fixed debugging of `catch` blocks (#10109)
 
 2021-02-26 4.2.1:

+ 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