2
0
Эх сурвалжийг харах

[java/cs] Fixed override overloaded generic functions that return Void. Closes #3171

Cauê Waneck 11 жил өмнө
parent
commit
2d5a4ae8e5

+ 3 - 2
gencommon.ml

@@ -10593,11 +10593,12 @@ struct
 								let old_args, old_ret = get_fun f.cf_type in
 								let args, ret = get_fun t in
 								let tf_args = List.map (fun (n,o,t) -> alloc_var n t, None) args in
+								let f3_mk_return = if is_void ret then (fun e -> e) else (fun e -> mk_return (mk_cast ret e)) in
 								f3.cf_expr <- Some {
 									eexpr = TFunction({
 										tf_args = tf_args;
 										tf_type = ret;
-										tf_expr = mk_block (mk_return (mk_cast ret {
+										tf_expr = mk_block (f3_mk_return {
 											eexpr = TCall(
 												{
 													eexpr = TField(
@@ -10609,7 +10610,7 @@ struct
 												List.map2 (fun (v,_) (_,_,t) -> mk_cast t (mk_local v p)) tf_args old_args);
 											etype = old_ret;
 											epos = p
-										}))
+										})
 									});
 									etype = t;
 									epos = p;

+ 47 - 0
tests/unit/issues/Issue3171.hx

@@ -0,0 +1,47 @@
+package unit.issues;
+
+class Issue3171 extends Test
+{
+#if (java || cs)
+	public function test()
+	{
+		var oint = new O2();
+		oint.foo(10);
+		eq(10,oint.lastVal);
+		f(oint.called);
+
+		var oint2:O<Int> = new O();
+		oint2.foo(10);
+		eq(0,oint2.lastVal);
+		t(oint2.called);
+
+		oint2 = new O2();
+		oint2.foo(20);
+		eq(20, oint2.lastVal);
+		f(oint2.called);
+	}
+#end
+}
+#if (java || cs)
+class O<T>
+{
+	public var lastVal = 0;
+	public var called = false;
+	public function new()
+	{
+	}
+
+	@:overload public function foo(t:T):Void
+	{
+		called = true;
+	}
+}
+
+class O2 extends O<Int>
+{
+	@:overload override public function foo(t:Int):Void
+	{
+		lastVal = t;
+	}
+}
+#end