Procházet zdrojové kódy

[java] Make sure that null arguments are seen as the Haxe compiler sees them when a function has type parameters

Otherwise javac seems to randomly select Object as the type parameter type

Closes #4360
Cauê Waneck před 9 roky
rodič
revize
977a309e36

+ 2 - 2
src/generators/gencommon.ml

@@ -6475,9 +6475,9 @@ struct
 					(* check types list *)
 					let new_ecall, elist = try
 						let elist = List.map2 (fun applied (_,_,funct) ->
-							match is_overload, applied.eexpr with
+							match is_overload || real_fparams <> [], applied.eexpr with
 							| true, TConst TNull ->
-								local_mk_cast (gen.greal_type funct) applied
+								mk_castfast (gen.greal_type funct) applied
 							| true, _ -> (* when not (type_iseq gen (gen.greal_type applied.etype) funct) -> *)
 								let ret = handle_cast gen applied (funct) (gen.greal_type applied.etype) in
 								(match ret.eexpr with

+ 21 - 0
tests/unit/src/unit/issues/Issue4360.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+class Issue4360<T> extends Test {
+	public function test() {
+		//this fails
+		var t : Abstr<Item> = new Abstr();
+		//but this works
+		// var t : Abstr<Item> = new Abstr(new Test());
+		eq(t, null);
+	}
+}
+
+private abstract Abstr<T>(Issue4360<T>) to Issue4360<T> {
+	public function new (inst:Issue4360<T> = null) : Void {
+		this = inst;
+	}
+}
+
+private class Item {
+    public function new () : Void { }
+}