Browse Source

[java] Tests some already closed issues, and closes #3123 by always casting the return type of functions with type parameters on Java. Closes #2282 . Closes #2540

Cauê Waneck 11 years ago
parent
commit
6c2cfce66a
4 changed files with 73 additions and 1 deletions
  1. 8 1
      gencommon.ml
  2. 24 0
      tests/unit/issues/Issue2282.hx
  3. 28 0
      tests/unit/issues/Issue2540.hx
  4. 13 0
      tests/unit/issues/Issue3123.hx

+ 8 - 1
gencommon.ml

@@ -6153,7 +6153,14 @@ struct
 						{ ecall with eexpr = TCall({ e1 with eexpr = TField(!ef, f) }, elist) }, elist
 					in
 					let new_ecall = if fparams <> [] then gen.gparam_func_call new_ecall { e1 with eexpr = TField(!ef, f) } fparams elist else new_ecall in
-					handle_cast gen new_ecall (gen.greal_type ecall.etype) (gen.greal_type ret_ft)
+					let ret = handle_cast gen new_ecall (gen.greal_type ecall.etype) (gen.greal_type ret_ft) in
+					(match gen.gcon.platform, cf.cf_params, ret.eexpr with
+						| _, _, TCast _ -> ret
+						| Java, _ :: _, _ ->
+							(* this is a workaround for a javac openjdk issue with unused type parameters and return type inference *)
+							(* see more at issue #3123 *)
+							mk_cast (gen.greal_type ret_ft) new_ecall
+						| _ -> ret)
 				end
 		| FClassField (cl,params,_,{ cf_kind = (Method MethDynamic | Var _) },_,actual_t,_) ->
 			(* if it's a var, we will just try to apply the class parameters that have been changed with greal_type_param *)

+ 24 - 0
tests/unit/issues/Issue2282.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+class Issue2282 extends Test
+{
+    function test() {
+			var f = new Foo();
+			eq(null,f.val);
+    }
+}
+
+
+private class Foo<T>
+{
+	public var val(get,null):T;
+	public function new()
+	{
+	}
+
+	public function get_val():T
+	{
+		return null;
+	}
+}
+

+ 28 - 0
tests/unit/issues/Issue2540.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+class Issue2540 extends Test
+{
+    function test() {
+			var r = new T();
+			eq(42,r.whatever());
+			var r:Foo<Dynamic> = new T();
+			eq(42,r.whatever());
+    }
+}
+
+private interface Foo<T>
+{
+	function whatever<X>():Int;
+}
+
+
+private class T implements Foo<Dynamic> {
+	public function new()
+	{
+	}
+
+	public function whatever<X>():Int
+	{
+		return 42;
+	}
+}

+ 13 - 0
tests/unit/issues/Issue3123.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+using Lambda;
+
+class Issue3123 extends Test
+{
+	function test() {
+		var a = [1, 2, 3];
+		var b = [1, 2];
+
+		var length = a.filter(function(v) { return b.exists(function(v2) { return v == v2; } ); } );
+		eq(2,length.count());
+	}
+}