2
0
Эх сурвалжийг харах

fix multiple `from` suitable for Array<Dynamic>
fixes #8203

Aleksandr Kuzmenko 6 жил өмнө
parent
commit
e661456f38

+ 13 - 3
src/typing/typer.ml

@@ -2072,6 +2072,7 @@ and type_local_function ctx name inline f with_type p =
 			mk (TMeta ((Meta.MergeBlock, [], null_pos), block)) v.v_type p
 
 and type_array_decl ctx el with_type p =
+	let allow_array_dynamic = ref false in
 	let tp = (match with_type with
 	| WithType.WithType(t,_) ->
 		let rec loop seen t =
@@ -2079,7 +2080,9 @@ and type_array_decl ctx el with_type p =
 			| TInst ({ cl_path = [],"Array" },[tp]) ->
 				(match follow tp with
 				| TMono _ -> None
-				| _ -> Some tp)
+				| _ as t ->
+					if t == t_dynamic then allow_array_dynamic := true;
+					Some tp)
 			| TAnon _ ->
 				(try
 					Some (get_iterable_param t)
@@ -2099,7 +2102,12 @@ and type_array_decl ctx el with_type p =
 				| [t] -> Some t
 				| _ -> None)
 			| t ->
-				if t == t_dynamic then Some t else None)
+				if t == t_dynamic then begin
+					allow_array_dynamic := true;
+					Some t
+				end else
+					None
+			)
 		in
 		loop [] t
 	| _ ->
@@ -2111,7 +2119,9 @@ and type_array_decl ctx el with_type p =
 		let t = try
 			unify_min_raise ctx.com.basic el
 		with Error (Unify l,p) ->
-			if ctx.untyped || ctx.com.display.dms_error_policy = EPIgnore then t_dynamic else begin
+			if !allow_array_dynamic || ctx.untyped || ctx.com.display.dms_error_policy = EPIgnore then
+				t_dynamic
+			else begin
 				display_error ctx "Arrays of mixed types are only allowed if the type is forced to Array<Dynamic>" p;
 				raise (Error (Unify l, p))
 			end

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

@@ -0,0 +1,16 @@
+package unit.issues;
+
+import utest.Assert;
+
+class Issue8203 extends unit.Test {
+	function test() {
+		var x:Dummy = [1,true,"hi"];
+		noAssert();
+	}
+}
+
+private abstract Dummy(Dynamic)
+	from Dynamic
+	from Array<Dynamic>
+	from Array<Int>
+{}