Переглянути джерело

[jvm] count closures on class instead of method

see #10571
Simon Krajewski 3 роки тому
батько
коміт
ac64a5fb82

+ 11 - 0
src/generators/jvm/jvmClass.ml

@@ -40,6 +40,7 @@ class builder path_this path_super = object(self)
 	val methods = DynArray.create ()
 	val method_sigs = Hashtbl.create 0
 	val inner_classes = Hashtbl.create 0
+	val closure_ids_per_name = Hashtbl.create 0
 	val mutable spawned_methods = []
 	val mutable static_init_method = None
 	val mutable source_file = None
@@ -78,6 +79,16 @@ class builder path_this path_super = object(self)
 	method has_method (name : string) (jsig : jsignature) =
 		Hashtbl.mem method_sigs (name,generate_method_signature false jsig)
 
+	method get_next_closure_id (name : string) =
+		try
+			let r = Hashtbl.find closure_ids_per_name name in
+			incr r;
+			!r
+		with Not_found ->
+			let r = ref 0 in
+			Hashtbl.add closure_ids_per_name name r;
+			!r
+
 	method spawn_inner_class (jm : JvmMethod.builder option) (path_super : jpath) (name : string option) =
 		let path = match name with
 			| None -> (fst path_this,Printf.sprintf "%s$%i" (snd path_this) (Hashtbl.length inner_classes))

+ 1 - 1
src/generators/jvm/jvmFunctions.ml

@@ -383,7 +383,7 @@ class typed_function
 	val jc_closure =
 		let name = match kind with
 			| FuncLocal ->
-				Printf.sprintf "Closure_%s_%i" (patch_name host_method#get_name) host_method#get_next_closure_id
+				Printf.sprintf "Closure_%s_%i" (patch_name host_method#get_name) (host_class#get_next_closure_id (host_method#get_name))
 			| FuncStatic(path,name) ->
 				Printf.sprintf "%s_%s" (snd path) (patch_name name)
 			| FuncMember(path,name) ->

+ 0 - 6
src/generators/jvm/jvmMethod.ml

@@ -143,7 +143,6 @@ class builder jc name jsig = object(self)
 	val mutable argument_locals = []
 	val mutable argument_annotations = Hashtbl.create 0
 	val mutable thrown_exceptions = Hashtbl.create 0
-	val mutable closure_count = 0
 	val mutable regex_count = 0
 
 	(* per-frame *)
@@ -192,11 +191,6 @@ class builder jc name jsig = object(self)
 			| _ -> JvmVerificationTypeInfo.of_signature jc#get_pool t
 		) locals
 
-	method get_next_closure_id =
-		let id = closure_count in
-		closure_count <- closure_count + 1;
-		id
-
 	method get_next_regex_id =
 		let id = regex_count in
 		regex_count <- regex_count + 1;

+ 24 - 0
tests/unit/src/unit/issues/Issue10571.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+class Issue10571 extends Test {
+	#if java
+	function test() {
+		eq("test()", foo());
+		eq("test(I)", foo(1));
+	}
+
+	overload static function foo() {
+		function x() {
+			return "test()";
+		}
+		return x();
+	}
+
+	overload static function foo(i:Int) {
+		function x() {
+			return "test(I)";
+		}
+		return x();
+	}
+	#end
+}