Browse Source

[analyzer] check the right expression when const-propagating assignments (closes #5221)

Simon Krajewski 9 years ago
parent
commit
9c737f9563
2 changed files with 12 additions and 1 deletions
  1. 1 1
      src/optimization/analyzer.ml
  2. 11 0
      tests/unit/src/unit/issues/Issue5221.hx

+ 1 - 1
src/optimization/analyzer.ml

@@ -465,7 +465,7 @@ module ConstPropagation = DataFlow(struct
 				end
 			| TBinop((OpAssign | OpAssignOp _ as op),({eexpr = TLocal v} as e1),e2) ->
 				let e2 = try
-					if (Optimizer.has_side_effect e1) then raise Not_found;
+					if (Optimizer.has_side_effect e2) then raise Not_found;
 					inline e2 v.v_id
 				with Not_found ->
 					commit e2

+ 11 - 0
tests/unit/src/unit/issues/Issue5221.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue5221 extends unit.Test {
+	static var ip(default,default):Int = -1;
+	function test() {
+		var ip2 = ip;
+		ip2 = ip = 0;
+		eq(0, ip2);
+		eq(0, ip);
+	}
+}