فهرست منبع

don't lose side-effects when propagating constants (closes #4743)

Simon Krajewski 9 سال پیش
والد
کامیت
bb120a6691
2فایلهای تغییر یافته به همراه27 افزوده شده و 2 حذف شده
  1. 7 2
      analyzer.ml
  2. 20 0
      tests/unit/src/unit/issues/Issue4743.hx

+ 7 - 2
analyzer.ml

@@ -1772,9 +1772,14 @@ module ConstPropagation = DataFlow(struct
 					e
 				end
 			| TBinop((OpAssign | OpAssignOp _ as op),({eexpr = TLocal v} as e1),e2) ->
-				let e2 = try inline e2 v.v_id with Not_found -> commit e2 in
+				let e2 = try
+					if (Optimizer.has_side_effect e1) then raise Not_found;
+					inline e2 v.v_id
+				with Not_found ->
+					commit e2
+				in
 				{e with eexpr = TBinop(op,e1,e2)}
-			| TVar(v,Some e1) ->
+			| TVar(v,Some e1) when not (Optimizer.has_side_effect e1) ->
 				let e1 = try inline e1 v.v_id with Not_found -> commit e1 in
 				{e with eexpr = TVar(v,Some e1)}
 			| _ ->

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

@@ -0,0 +1,20 @@
+package unit.issues;
+
+import unit.Test;
+
+/**
+ * ...
+ * @author
+ */
+class Issue4743 extends Test{
+	static var i(default, set):Int = 0;
+	static function set_i(value) return i = value;
+
+	static var j:Int = 0;
+
+	public function test() {
+		i = j = 1;
+		eq(1, i);
+		eq(1, j);
+	}
+}