2
0
Эх сурвалжийг харах

[all] Merged Simn's fix to #3090 and fixed C#'s issue with it. Closes #3090

Cauê Waneck 10 жил өмнө
parent
commit
7b653f5790

+ 13 - 0
codegen.ml

@@ -291,6 +291,13 @@ let has_ctor_constraint c = match c.cl_kind with
 		) tl;
 	| _ -> false
 
+let get_short_name =
+	let i = ref (-1) in
+	(fun () ->
+		incr i;
+		Printf.sprintf "__hx_type_%i" !i
+	)
+
 let rec build_generic ctx c p tl =
 	let pack = fst c.cl_path in
 	let recurse = ref false in
@@ -451,6 +458,12 @@ let rec build_generic ctx c p tl =
 			cg.cl_fields <- PMap.add f.cf_name f cg.cl_fields;
 			f
 		) c.cl_ordered_fields;
+		(* In rare cases the class name can become too long, so let's shorten it (issue #3090). *)
+		if String.length (snd cg.cl_path) > 254 then begin
+			let n = get_short_name () in
+			let tp = fst cg.cl_path,n in
+			cg.cl_meta <- (Meta.Native,[EConst(String (s_type_path tp)),p],p) :: cg.cl_meta;
+		end;
 		TInst (cg,[])
 	end
 

+ 10 - 3
gencommon.ml

@@ -1015,7 +1015,11 @@ let dump_descriptor gen name path_s module_s =
 	let main_paths = Hashtbl.create 0 in
 	List.iter (fun md_def ->
 		SourceWriter.write w "M ";
-		SourceWriter.write w (path_s md_def.m_path);
+		let path = match md_def.m_types with
+			| [TClassDecl c] -> c.cl_path
+			| _ -> md_def.m_path
+		in
+		SourceWriter.write w (path_s path);
 		SourceWriter.newline w;
 		List.iter (fun m ->
 			match m with
@@ -1151,8 +1155,11 @@ let generate_modules gen extension source_dir (module_gen : SourceWriter.source_
 		(*let should_write = List.fold_left (fun should md -> module_gen w md or should) false md_def.m_types in*)
 		let should_write = module_gen w md_def in
 		if should_write then begin
-			let path = md_def.m_path in
-			write_file gen w source_dir path extension out_files
+			let path = match md_def.m_types with
+				| [TClassDecl c] -> c.cl_path
+				| _ -> md_def.m_path
+			in
+			write_file gen w source_dir path extension out_files;
 		end
 	) gen.gcon.modules
 

+ 12 - 0
tests/unit/issues/Issue3090.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+import haxe.xml.Printer;
+@:generic
+private class A<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>{
+    public function new(){}
+}
+
+class Issue3090 extends Test {
+	function test() {
+		var a = new A<Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer,Printer>();
+	}
+}