Browse Source

make sure invalid field access is seen when inlining constructors (closes #5931)

Simon Krajewski 8 years ago
parent
commit
1ab45f4991

+ 3 - 2
src/optimization/optimizer.ml

@@ -1235,11 +1235,12 @@ let inline_constructors ctx e =
 								e :: acc
 							| _ -> acc
 						) el_init c.cl_ordered_fields in
-						let e = match el_init with
+						let e' = match el_init with
 							| [] -> e
 							| _ -> mk (TBlock (List.rev (e :: el_init))) e.etype e.epos
 						in
-						add v e (IKCtor(cf,c.cl_extern || Meta.has Meta.Extern cf.cf_meta));
+						add v e' (IKCtor(cf,c.cl_extern || Meta.has Meta.Extern cf.cf_meta));
+						find_locals e
 					| None ->
 						()
 					end

+ 6 - 3
tests/optimization/src/Test.hx

@@ -51,11 +51,12 @@ class Test {
 
 	@:js('
 		var a = 0;
+		var c_y;
 		var c_x;
 		a = 1;
 		a = 2;
 		c_x = 12;
-		var c_y = "foo";
+		c_y = "foo";
 		a = 12;
 	')
 	static function testInlineCtor2() {
@@ -70,12 +71,14 @@ class Test {
 
 	@:js('
 		var a = 0;
+		var b_y;
 		var b_x;
+		var c_y;
 		var c_x = 1;
-		var c_y = "c";
+		c_y = "c";
 		a = 1;
 		b_x = 2;
-		var b_y = "b";
+		b_y = "b";
 		b_x = 1;
 	')
 	static function testInlineCtor3() {

+ 23 - 0
tests/optimization/src/issues/Issue5931.hx

@@ -0,0 +1,23 @@
+package issues;
+
+class Issue5931 {
+	inline function something(arg:Int, func) {
+		var func1 = func;
+		func1(arg);
+	}
+
+	function callback(arg:Int) {
+		trace('here1');
+	}
+
+	inline function new() {
+		something(1, callback);
+	}
+
+	@:js('
+		new issues_Issue5931();
+	')
+	static public function main() {
+		var x = new Issue5931();
+	}
+}