Browse Source

[analyzer] avoid some temp vars (closes #4322)

Simon Krajewski 10 years ago
parent
commit
a9674e4a94
2 changed files with 21 additions and 0 deletions
  1. 1 0
      analyzer.ml
  2. 20 0
      tests/unit/src/unit/issues/Issue4322.hx

+ 1 - 0
analyzer.ml

@@ -365,6 +365,7 @@ module Simplifier = struct
 				let e1 = match e1.eexpr with
 					| TFunction _ -> loop e1
 					| TArrayDecl [{eexpr = TFunction _}] -> loop e1
+					| TNew(_,_,el) when not (List.exists Optimizer.has_side_effect el) -> loop e1 (* issue #4322 *)
 					| _ -> bind ~allow_tlocal:true e1
 				in
 				{e with eexpr = TVar(v,Some e1)}

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

@@ -0,0 +1,20 @@
+package unit.issues;
+
+private class InlineTest {
+	public var a: Int;
+	public var b: Int;
+
+	@:extern
+	public inline function new(a: Int, b: Int) {
+		this.a = a;
+		this.b = b;
+	}
+}
+
+class Issue4322 extends Test {
+	function test() {
+		var c = new InlineTest(3, 4);
+		eq(3, c.a);
+		eq(4, c.b);
+	}
+}