Browse Source

[jvm] generate type parameter constraints into signatures

closes #9536
Simon Krajewski 5 years ago
parent
commit
5731e75e59
2 changed files with 21 additions and 4 deletions
  1. 11 1
      src/generators/genjvm.ml
  2. 10 3
      src/generators/jvm/jvmClass.ml

+ 11 - 1
src/generators/genjvm.ml

@@ -2495,7 +2495,17 @@ class tclass_to_jvm gctx c = object(self)
 		end
 
 	method private generate_signature =
-		jc#set_type_parameters (List.map fst c.cl_params);
+		jc#set_type_parameters (List.map (fun (n,t) ->
+			let jsigs = match follow t with
+			| TInst({cl_kind = KTypeParameter tl},_) ->
+				List.map (fun t ->
+					get_boxed_type (jsignature_of_type gctx t)
+				 ) tl
+			| _ ->
+				[]
+			in
+			(n,jsigs)
+		) c.cl_params);
 		match c.cl_super with
 			| Some(c,tl) -> jc#set_super_parameters (List.map (jtype_argument_of_type gctx []) tl)
 			| _ -> ()

+ 10 - 3
src/generators/jvm/jvmClass.ml

@@ -48,7 +48,7 @@ class builder path_this path_super = object(self)
 		interface_offsets <- (pool#add_path path) :: interface_offsets;
 		interfaces <- (path,params) :: interfaces
 
-	method set_type_parameters (sl : string list) =
+	method set_type_parameters (sl : (string * jsignature list) list) =
 		type_parameters <- sl
 
 	method set_super_parameters (params : jtype_argument list) =
@@ -153,8 +153,15 @@ class builder path_this path_super = object(self)
 		let stl = match type_parameters with
 			| [] -> ""
 			| params ->
-				let stl = String.concat "" (List.map (fun n ->
-					Printf.sprintf "%s:Ljava/lang/Object;" n
+				let stl = String.concat "" (List.map (fun (n,jsigs) ->
+					let jsigs = match jsigs with
+						| [] -> [object_sig]
+						| _ -> jsigs
+					in
+					let s = String.concat "" (List.map (fun jsig ->
+						Printf.sprintf ":%s" (generate_signature true jsig)
+					) jsigs) in
+					Printf.sprintf "%s%s" n s
 				) params) in
 				Printf.sprintf "<%s>" stl
 		in