Browse Source

[analyzer] do not mess up captured variable ops (closes #5432)

Simon Krajewski 9 years ago
parent
commit
68620bb8ba

+ 1 - 1
src/optimization/analyzerTexprTransformer.ml

@@ -668,7 +668,7 @@ and func ctx i =
 					false
 			in
 			begin match e1.eexpr,e2.eexpr with
-				| TLocal v1,TLocal v2 when v1 == v2 && is_valid_assign_op op ->
+				| TLocal v1,TLocal v2 when v1 == v2 && not v1.v_capture && is_valid_assign_op op ->
 					begin match op,e3.eexpr with
 						| OpAdd,TConst (TInt i32) when Int32.to_int i32 = 1 && target_handles_assign_ops ctx.com -> {e with eexpr = TUnop(Increment,Prefix,e1)}
 						| OpSub,TConst (TInt i32) when Int32.to_int i32 = 1 && target_handles_assign_ops ctx.com -> {e with eexpr = TUnop(Decrement,Prefix,e1)}

+ 25 - 0
tests/unit/src/unit/issues/Issue5432.hx

@@ -0,0 +1,25 @@
+package unit.issues;
+
+class Issue5432 extends unit.Test {
+	function test() {
+		var pt = new Point();
+
+		function closure()
+		{
+			pt.x = pt.x + pt.y;
+		}
+
+		closure();
+		feq(3., pt.x);
+		feq(2., pt.y);
+	}
+
+}
+
+private class Point
+{
+	public var x:Float = 1;
+	public var y:Float = 2;
+
+	@:extern inline public function new() {}
+}