Просмотр исходного кода

don't try to binop-optimize things that aren't Int or Float

closes #12031
Simon Krajewski 6 месяцев назад
Родитель
Сommit
c92489123e
2 измененных файлов с 31 добавлено и 1 удалено
  1. 1 1
      src/optimization/optimizerTexpr.ml
  2. 30 0
      tests/unit/src/unit/issues/Issue12031.hx

+ 1 - 1
src/optimization/optimizerTexpr.ml

@@ -109,7 +109,7 @@ let optimize_binop e op e1 e2 =
 		| OpEq -> { e with eexpr = TConst (TBool false) }
 		| OpNotEq -> { e with eexpr = TConst (TBool true) }
 		| _ -> e)
-	| TConst (TInt a), TConst (TInt b) ->
+	| TConst (TInt a), TConst (TInt b) when is_numeric  e1.etype && is_numeric e2.etype ->
 		let opt f = try { e with eexpr = TConst (TInt (f a b)) } with Exit -> e in
 		let check_overflow f =
 			opt (fun a b ->

+ 30 - 0
tests/unit/src/unit/issues/Issue12031.hx

@@ -0,0 +1,30 @@
+package unit.issues;
+
+import utest.Assert;
+
+class Issue12031 extends Test {
+	#if hl
+	inline function inlinef(v:hl.I64) {
+		var str = "";
+		str += (v >> 32);
+		return str;
+	}
+
+	function noInlinef(v:hl.I64) {
+		var str = "";
+		str += (v >> 32);
+		return str;
+	}
+
+	function test() {
+		var base:hl.I64 = 22; // 0b10110
+		eq(22, base.toInt());
+		eq("0", inlinef(base));
+		eq("0", noInlinef(base));
+		var manual1 = "" + (base >> 33);
+		eq("0", manual1);
+		var manual2 = "" + (base >> 34);
+		eq("0", manual2);
+	}
+	#end
+}