Explorar o código

[analyzer] don't fuse into write-positions

closes #7298
Simon Krajewski %!s(int64=7) %!d(string=hai) anos
pai
achega
3c6d1bd0a4
Modificáronse 2 ficheiros con 15 adicións e 0 borrados
  1. 3 0
      src/optimization/analyzerTexpr.ml
  2. 12 0
      tests/unit/src/unit/issues/Issue7298.hx

+ 3 - 0
src/optimization/analyzerTexpr.ml

@@ -874,6 +874,9 @@ module Fusion = struct
 							let e2 = replace e2 in
 							if not !found && has_var_read ir v then raise Exit;
 							{e with eexpr = TBinop(OpAssign,e1,e2)}
+						(* Never fuse into write-positions (issue #7298) *)
+						| TBinop(OpAssignOp _,{eexpr = TLocal v2},_) | TUnop((Increment | Decrement),_,{eexpr = TLocal v2}) when v1 == v2 ->
+							raise Exit
 						| TBinop(OpAssignOp _ as op,({eexpr = TLocal v} as e1),e2) ->
 							let e2 = replace e2 in
 							if not !found && (has_var_read ir v || has_var_write ir v) then raise Exit;

+ 12 - 0
tests/unit/src/unit/issues/Issue7298.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+class Issue7298 extends unit.Test {
+	static var _pageIndex = 0;
+	function test() {
+		var currentPageIndex = _pageIndex;
+    	var r = _updatePageIndexSelection(++currentPageIndex);
+		eq(0, r);
+	}
+
+	static function _updatePageIndexSelection(v:Int) return _pageIndex;
+}