2
0
Эх сурвалжийг харах

loop through TMeta when "sanitizing" unops and binops (hopefully closes #5508)

Dan Korostelev 9 жил өмнө
parent
commit
f193e4a2d1

+ 2 - 2
src/optimization/optimizer.ml

@@ -999,7 +999,7 @@ let sanitize_expr com e =
 			match ee.eexpr with
 			match ee.eexpr with
 			| TBinop (op2,_,_) -> if left then not (swap op2 op) else swap op op2
 			| TBinop (op2,_,_) -> if left then not (swap op2 op) else swap op op2
 			| TIf _ -> if left then not (swap (OpAssignOp OpAssign) op) else swap op (OpAssignOp OpAssign)
 			| TIf _ -> if left then not (swap (OpAssignOp OpAssign) op) else swap op (OpAssignOp OpAssign)
-			| TCast (e,None) -> loop e left
+			| TCast (e,None) | TMeta (_,e) -> loop e left
 			| _ -> false
 			| _ -> false
 		in
 		in
 		let e1 = if loop e1 true then parent e1 else e1 in
 		let e1 = if loop e1 true then parent e1 else e1 in
@@ -1009,7 +1009,7 @@ let sanitize_expr com e =
 		let rec loop ee =
 		let rec loop ee =
 			match ee.eexpr with
 			match ee.eexpr with
 			| TBinop _ | TIf _ | TUnop _ -> parent e1
 			| TBinop _ | TIf _ | TUnop _ -> parent e1
-			| TCast (e,None) -> loop e
+			| TCast (e,None) | TMeta (_, e) -> loop e
 			| _ -> e1
 			| _ -> e1
 		in
 		in
 		{ e with eexpr = TUnop (op,mode,loop e1)}
 		{ e with eexpr = TUnop (op,mode,loop e1)}

+ 14 - 0
tests/unit/src/unit/issues/Issue5508.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue5508 extends unit.Test {
+    var i = 2;
+
+	function test() {
+		eq(~mask(i), -5);
+	}
+
+    @:pure
+    inline static function mask(i:Int):Int {
+        return 0x1 << i;
+    }
+}