Forráskód Böngészése

fix @:structInit ctor arguments order (#9418)

Aleksandr Kuzmenko 5 éve
szülő
commit
6dad667ae8

+ 1 - 0
extra/CHANGES.txt

@@ -2,6 +2,7 @@
 
 	Bugfixes:
 
+	all : fixed arguments ordering for @:structInit constructors (#9418)
 	js/cpp : fixed catch var naming collision (#9413)
 	interp : fixed throwing `haxe.macro.Error` outside of a macro context (#9390)
 

+ 3 - 3
src/typing/typeloadFields.ml

@@ -137,7 +137,7 @@ let get_struct_init_super_info ctx c p =
 	match c.cl_super with
 		| Some ({ cl_constructor = Some ctor } as csup, cparams) ->
 			let args = (try get_method_args ctor with Not_found -> []) in
-			let tl,el =
+			let tl_rev,el_rev =
 				List.fold_left (fun (args,exprs) (v,value) ->
 					let opt = match value with
 						| Some _ -> true
@@ -147,8 +147,8 @@ let get_struct_init_super_info ctx c p =
 					(v.v_name,opt,t) :: args,(mk (TLocal v) v.v_type p) :: exprs
 				) ([],[]) args
 			in
-			let super_expr = mk (TCall (mk (TConst TSuper) (TInst (csup,cparams)) p, el)) ctx.t.tvoid p in
-			(args,Some super_expr,tl)
+			let super_expr = mk (TCall (mk (TConst TSuper) (TInst (csup,cparams)) p, List.rev el_rev)) ctx.t.tvoid p in
+			(args,Some super_expr,List.rev tl_rev)
 		| _ ->
 			[],None,[]
 

+ 20 - 0
tests/unit/src/unit/issues/Issue9418.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+class Issue9418 extends unit.Test {
+	function test() {
+		var c:GrandChild = {int: 42, string: 'hi'};
+		eq(42, c.int);
+		eq('hi', c.string);
+	}
+}
+
+@:structInit private class Base {
+	public final string:String;
+	public final int:Int;
+}
+
+@:structInit private class Child extends Base {
+}
+
+@:structInit private class GrandChild extends Child {
+}