Sfoglia il codice sorgente

[cs] move generation of GenericInterface attribute to gencs where proper escaping is available (closes #4116)

Dan Korostelev 10 anni fa
parent
commit
bd55c70050

+ 6 - 7
gencommon.ml

@@ -4815,13 +4815,12 @@ struct
 							let iface = mk_class cl.cl_module cl.cl_path cl.cl_pos in
 							iface.cl_array_access <- Option.map (apply_params (cl.cl_params) (List.map (fun _ -> t_dynamic) cl.cl_params)) cl.cl_array_access;
 							iface.cl_module <- cl.cl_module;
-							iface.cl_meta <- (Meta.HxGen, [], cl.cl_pos) :: iface.cl_meta;
-							if gen.gcon.platform = Cs then begin
-								let tparams = List.map (fun _ -> "object") cl.cl_params in
-								iface.cl_meta <- (Meta.Meta, [
-									EConst( String("haxe.lang.GenericInterface(typeof(" ^ path_s cl.cl_path ^ "<" ^ String.concat ", " tparams ^">))") ), cl.cl_pos
-								], cl.cl_pos) :: iface.cl_meta
-							end;
+							iface.cl_meta <-
+								(Meta.HxGen, [], cl.cl_pos)
+								::
+								(Meta.Custom "generic_iface", [(EConst(Int(string_of_int(List.length cl.cl_params))), cl.cl_pos)], cl.cl_pos)
+								::
+								iface.cl_meta;
 							Hashtbl.add ifaces cl.cl_path iface;
 
 							iface.cl_implements <- (base_generic, []) :: iface.cl_implements;

+ 16 - 0
gencs.ml

@@ -2362,6 +2362,22 @@ let configure gen =
 				begin_block w;
 				true
 		in
+
+		(try
+			let _,m,_ = Meta.get (Meta.Custom "generic_iface") cl.cl_meta in
+			let rec loop i acc =
+				if i == 0 then
+					acc
+				else
+					"object" :: (loop (pred i) acc)
+			in
+			let tparams = loop (match m with [(EConst(Int s),_)] -> int_of_string s | _ -> assert false) [] in
+			cl.cl_meta <- (Meta.Meta, [
+				EConst(String("global::haxe.lang.GenericInterface(typeof(global::" ^ module_s (TClassDecl cl) ^ "<" ^ String.concat ", " tparams ^ ">))") ), cl.cl_pos
+			], cl.cl_pos) :: cl.cl_meta
+		with Not_found ->
+			());
+
 		gen_attributes w cl.cl_meta;
 
 		let is_main =

+ 1 - 0
tests/misc/projects/Issue4116/.gitignore

@@ -0,0 +1 @@
+/cs

+ 3 - 0
tests/misc/projects/Issue4116/base/A.hx

@@ -0,0 +1,3 @@
+package base;
+
+class A<T> {}

+ 2 - 0
tests/misc/projects/Issue4116/compile.hxml

@@ -0,0 +1,2 @@
+-cs cs
+base.A