فهرست منبع

[analyzer] do not clean up unbound calls (closes #5309)

They could contain blocks, in which case cleanup messes up some things.
Simon Krajewski 9 سال پیش
والد
کامیت
0d5f85840e
2فایلهای تغییر یافته به همراه17 افزوده شده و 0 حذف شده
  1. 2 0
      src/optimization/analyzerTexpr.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue5309.hx

+ 2 - 0
src/optimization/analyzerTexpr.ml

@@ -606,6 +606,8 @@ module Cleanup = struct
 				let e2 = loop e2 in
 				let e3 = loop e3 in
 				if_or_op e e1 e2 e3;
+			| TCall({eexpr = TLocal v},_) when is_really_unbound v ->
+				e
 			| TBlock el ->
 				let el = List.map (fun e ->
 					let e = loop e in

+ 15 - 0
tests/unit/src/unit/issues/Issue5309.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue5309 extends unit.Test {
+	function test() {
+	  eq(25, f2b(0.1));
+	}
+
+	public static inline function clamp( f : Float, min = 0., max = 1. ) {
+		return f < min ? min : f > max ? max : f;
+	}
+
+	public static function f2b( v:Float ) : Int {
+		return Std.int(clamp(v) * 255.0);
+	}
+}