Procházet zdrojové kódy

[java/cs] Correctly set constructor arguments as capture. Closes #3578

Cauê Waneck před 11 roky
rodič
revize
7fbaed79b4
2 změnil soubory, kde provedl 28 přidání a 0 odebrání
  1. 1 0
      gencommon.ml
  2. 27 0
      tests/unit/src/unit/issues/Issue3578.hx

+ 1 - 0
gencommon.ml

@@ -1709,6 +1709,7 @@ struct
 			let local_map = Hashtbl.create (List.length cur_tf_args) in
 			let static_tf_args = (me, None) :: List.map (fun (v,b) ->
 				let new_v = alloc_var v.v_name (apply_params cl.cl_params ctor_params v.v_type) in
+				new_v.v_capture <- v.v_capture;
 				Hashtbl.add local_map v.v_id new_v;
 				(new_v, b)
 			) cur_tf_args in

+ 27 - 0
tests/unit/src/unit/issues/Issue3578.hx

@@ -0,0 +1,27 @@
+package unit.issues;
+
+class Issue3578 extends Test
+{
+	function test()
+	{
+		var i = 0;
+		var t = new TestG(function() i++);
+		eq(i,1);
+		t.func();
+		eq(i,2);
+	}
+}
+
+private class TestG
+{
+	public var func:Void->Void;
+	public function new(callback:Void->Void)
+	{
+		function x()
+		{
+			callback();
+		}
+		x();
+		this.func = x;
+	}
+}