ソースを参照

do not not-optimize Float comparisons (closes #4889)

Simon Krajewski 9 年 前
コミット
3027f56b57
2 ファイル変更17 行追加1 行削除
  1. 5 1
      optimizer.ml
  2. 12 0
      tests/unit/src/unit/issues/Issue4889.hx

+ 5 - 1
optimizer.ml

@@ -1213,9 +1213,13 @@ let optimize_binop e op e1 e2 =
 		e)
 
 let optimize_unop e op flag esub =
+	let is_int t = match follow t with
+		| TAbstract({a_path = [],"Int"},_) -> true
+		| _ -> false
+	in
 	match op, esub.eexpr with
 		| Not, (TConst (TBool f) | TParenthesis({eexpr = TConst (TBool f)})) -> { e with eexpr = TConst (TBool (not f)) }
-		| Not, (TBinop(op,e1,e2) | TParenthesis({eexpr = TBinop(op,e1,e2)})) ->
+		| Not, (TBinop(op,e1,e2) | TParenthesis({eexpr = TBinop(op,e1,e2)})) when is_int e1.etype && is_int e2.etype ->
 			begin try
 				let op = match op with
 					| OpGt -> OpLte

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

@@ -0,0 +1,12 @@
+package unit.issues;
+
+class Issue4889 extends Test {
+	function test() {
+		var f = getFloat();
+		t(!(f > Math.NaN));
+	}
+
+	static function getFloat() {
+		return 1.0;
+	}
+}