Browse Source

fixed rest arguments of `Dynamic` type (closes #10030)

Aleksandr Kuzmenko 4 years ago
parent
commit
076f1535c9
2 changed files with 30 additions and 2 deletions
  1. 14 2
      src/typing/callUnification.ml
  2. 16 0
      tests/unit/src/unit/issues/Issue10030.hx

+ 14 - 2
src/typing/callUnification.ml

@@ -137,8 +137,20 @@ let rec unify_call_args ctx el args r callp inline force_inline in_overload =
 									| _ -> punion p p2
 									| _ -> punion p p2
 								) p1 el
 								) p1 el
 							in
 							in
-							(try [type_against name t (EArrayDecl el,p)]
-							with WithTypeError(ul,p) -> arg_error ul name false p)
+							(try
+								let do_type e = [type_against name t e] in
+								let e = EArrayDecl el,p in
+								(* typer requires dynamic arrays to be explicitly declared as Array<Dynamic> *)
+								if follow arg_t == t_dynamic then begin
+									let dynamic = CTPath(mk_type_path ([],"Dynamic")),p in
+									let params = [TPType dynamic] in
+									let tp = mk_type_path ~params ([],"Array") in
+									do_type (ECheckType(e,(CTPath tp, p)),p) (* ([arg1, arg2...]:Array<Dynamic>) *)
+								end else
+									do_type e
+							with WithTypeError(ul,p) ->
+								arg_error ul name false p
+							)
 					end
 					end
 				| _ ->
 				| _ ->
 					die "" __LOC__
 					die "" __LOC__

+ 16 - 0
tests/unit/src/unit/issues/Issue10030.hx

@@ -0,0 +1,16 @@
+package unit.issues;
+
+class Issue10030 extends unit.Test {
+	function test() {
+		aeq(([1, true, 'hello']:Array<Dynamic>), restDynamic(1, true, 'hello'));
+		aeq(([2, false, 'world']:Array<Dynamic>), restAny(2, false, 'world'));
+	}
+
+	function restDynamic(...args:Dynamic) {
+		return args.toArray();
+	}
+
+	function restAny(...args:Any) {
+		return args.toArray();
+	}
+}