فهرست منبع

[inliner] object declarations are _not_ constants

closes #6480
Simon Krajewski 8 سال پیش
والد
کامیت
296758b1a9
2فایلهای تغییر یافته به همراه20 افزوده شده و 0 حذف شده
  1. 1 0
      src/optimization/optimizer.ml
  2. 19 0
      tests/unit/src/unit/issues/Issue6480.hx

+ 1 - 0
src/optimization/optimizer.ml

@@ -517,6 +517,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			| TLocal _
 			| TConst TThis (* not really, but should not be move inside a function body *)
 				-> raise Exit
+			| TObjectDecl _ | TArrayDecl _ -> raise Exit
 			| TField (_,FEnum _)
 			| TTypeExpr _
 			| TConst _ -> ()

+ 19 - 0
tests/unit/src/unit/issues/Issue6480.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+class Issue6480 extends unit.Test {
+	function test() {
+		var o_blub = (function(f,o) {
+			return function(increment) {
+				return f(o,increment);
+			};
+		})(blub,{ counter : 0});
+        eq(1, o_blub(true));
+        eq(2, o_blub(true));
+	}
+
+    static function blub(o:{ counter: Int}, increment:Bool) {
+        if (increment) o.counter++;
+        else o.counter--;
+        return o.counter;
+    }
+}