瀏覽代碼

[java] Only take off the type parameter when declaring native arrays of types with type parameter. Closes #3303

Cauê Waneck 11 年之前
父節點
當前提交
68064bdce5
共有 2 個文件被更改,包括 25 次插入2 次删除
  1. 11 2
      genjava.ml
  2. 14 0
      tests/unit/issues/Issue3303.hx

+ 11 - 2
genjava.ml

@@ -55,6 +55,7 @@ let unboxed_type gen t tbyte tshort tchar tfloat = match follow t with
 let rec t_has_type_param t = match follow t with
 let rec t_has_type_param t = match follow t with
 	| TInst({ cl_kind = KTypeParameter _ }, []) -> true
 	| TInst({ cl_kind = KTypeParameter _ }, []) -> true
 	| TEnum(_, params)
 	| TEnum(_, params)
+	| TAbstract(_, params)
 	| TInst(_, params) -> List.exists t_has_type_param params
 	| TInst(_, params) -> List.exists t_has_type_param params
 	| TFun(f,ret) -> t_has_type_param ret || List.exists (fun (_,_,t) -> t_has_type_param t) f
 	| TFun(f,ret) -> t_has_type_param ret || List.exists (fun (_,_,t) -> t_has_type_param t) f
 	| _ -> false
 	| _ -> false
@@ -66,10 +67,18 @@ let is_type_param t = match follow t with
 let rec t_has_type_param_shallow last t = match follow t with
 let rec t_has_type_param_shallow last t = match follow t with
 	| TInst({ cl_kind = KTypeParameter _ }, []) -> true
 	| TInst({ cl_kind = KTypeParameter _ }, []) -> true
 	| TEnum(_, params)
 	| TEnum(_, params)
+	| TAbstract(_, params)
 	| TInst(_, params) when not last -> List.exists (t_has_type_param_shallow true) params
 	| TInst(_, params) when not last -> List.exists (t_has_type_param_shallow true) params
 	| TFun(f,ret) when not last -> t_has_type_param_shallow true ret	|| List.exists (fun (_,_,t) -> t_has_type_param_shallow true t) f
 	| TFun(f,ret) when not last -> t_has_type_param_shallow true ret	|| List.exists (fun (_,_,t) -> t_has_type_param_shallow true t) f
 	| _ -> false
 	| _ -> false
 
 
+let rec replace_type_param t = match follow t with
+	| TInst({ cl_kind = KTypeParameter _ }, []) -> t_dynamic
+	| TEnum(e, params) -> TEnum(e, List.map replace_type_param params)
+	| TAbstract(a, params) -> TAbstract(a, List.map replace_type_param params)
+	| TInst(cl, params) -> TInst(cl, List.map replace_type_param params)
+	| _ -> t
+
 let is_java_basic_type t =
 let is_java_basic_type t =
 	match follow t with
 	match follow t with
 		| TInst( { cl_path = (["haxe"], "Int32") }, [] )
 		| TInst( { cl_path = (["haxe"], "Int32") }, [] )
@@ -1233,8 +1242,8 @@ let configure gen =
 				| TMeta (_,e) ->
 				| TMeta (_,e) ->
 					expr_s w e
 					expr_s w e
 				| TCall ({ eexpr = TLocal { v_name = "__array__" } }, el)
 				| TCall ({ eexpr = TLocal { v_name = "__array__" } }, el)
-				| TArrayDecl el when t_has_type_param_shallow false e.etype ->
-					print w "( (%s) (new java.lang.Object[] " (t_s e.epos e.etype);
+				| TArrayDecl el when t_has_type_param e.etype ->
+					print w "( (%s) (new %s " (t_s e.epos e.etype) (t_s e.epos (replace_type_param e.etype));
 					write w "{";
 					write w "{";
 					ignore (List.fold_left (fun acc e ->
 					ignore (List.fold_left (fun acc e ->
 						(if acc <> 0 then write w ", ");
 						(if acc <> 0 then write w ", ");

+ 14 - 0
tests/unit/issues/Issue3303.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+import haxe.ds.Vector;
+
+class Issue3303 extends Test {
+	function test() {
+		var ret = createClosure(null);
+		eq(null,ret());
+	}
+
+	static function createClosure<T>(v:Vector<T>):Void->Vector<T>
+	{
+		return function() return v;
+	}
+}