Browse Source

[inliner] don't eliminate callback args if actually called
fixes #8986

Aleksandr Kuzmenko 5 năm trước cách đây
mục cha
commit
77665efc43
2 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 1 1
      src/optimization/inline.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue8986.hx

+ 1 - 1
src/optimization/inline.ml

@@ -585,7 +585,7 @@ class inline_state ctx ethis params cf f p = object(self)
 			| TVar (v, Some { eexpr = TConst _ }) ->
 				(try
 					let data = Hashtbl.find locals v.v_id in
-					if data.i_read = 0 && not data.i_write then mk (TBlock []) e.etype e.epos
+					if data.i_read = 0 && data.i_called = 0 && not data.i_write then mk (TBlock []) e.etype e.epos
 					else Type.map_expr drop_unused_vars e
 				with Not_found ->
 					Type.map_expr drop_unused_vars e

+ 13 - 0
tests/unit/src/unit/issues/Issue8986.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue8986 extends unit.Test {
+	function test() {
+		try invoke(null)
+		catch(_:Dynamic) {}
+		noAssert();
+	}
+
+	static inline function invoke(f:(item:Int)->Void) {
+		f(1);
+	}
+}