Browse Source

skip TMeta in the sanitizer when determining parens (closes #5508)

Simon Krajewski 9 years ago
parent
commit
11ccd6fa5d
2 changed files with 19 additions and 5 deletions
  1. 2 2
      src/optimization/optimizer.ml
  2. 17 3
      tests/unit/src/unit/issues/Issue5508.hx

+ 2 - 2
src/optimization/optimizer.ml

@@ -950,8 +950,8 @@ let standard_precedence op =
 
 
 let rec need_parent e =
 let rec need_parent e =
 	match e.eexpr with
 	match e.eexpr with
-	| TConst _ | TLocal _ | TArray _ | TField _ | TEnumParameter _ | TParenthesis _ | TMeta _ | TCall _ | TNew _ | TTypeExpr _ | TObjectDecl _ | TArrayDecl _ -> false
-	| TCast (e,None) -> need_parent e
+	| TConst _ | TLocal _ | TArray _ | TField _ | TEnumParameter _ | TParenthesis _ | TCall _ | TNew _ | TTypeExpr _ | TObjectDecl _ | TArrayDecl _ -> false
+	| TCast (e,None) | TMeta(_,e) -> need_parent e
 	| TCast _ | TThrow _ | TReturn _ | TTry _ | TSwitch _ | TFor _ | TIf _ | TWhile _ | TBinop _ | TContinue | TBreak
 	| TCast _ | TThrow _ | TReturn _ | TTry _ | TSwitch _ | TFor _ | TIf _ | TWhile _ | TBinop _ | TContinue | TBreak
 	| TBlock _ | TVar _ | TFunction _ | TUnop _ -> true
 	| TBlock _ | TVar _ | TFunction _ | TUnop _ -> true
 
 

+ 17 - 3
tests/unit/src/unit/issues/Issue5508.hx

@@ -1,14 +1,28 @@
 package unit.issues;
 package unit.issues;
 
 
+private class C {
+	public var f:Int;
+	public function new() {
+		f = 1;
+	}
+}
+
 class Issue5508 extends unit.Test {
 class Issue5508 extends unit.Test {
-    var i = 2;
+	var i = 2;
+	static var c = new C();
 
 
 	function test() {
 	function test() {
 		eq(~mask(i), -5);
 		eq(~mask(i), -5);
+		eq(nPure(c).f, 1);
+	}
+
+	@:pure
+	inline static function mask(i:Int):Int {
+		return 0x1 << i;
 	}
 	}
 
 
     @:pure
     @:pure
-    inline static function mask(i:Int):Int {
-        return 0x1 << i;
+    static inline function nPure(a:C) {
+        return if (a == null) a else a;
     }
     }
 }
 }