Browse Source

[jvm] refer to static instance methods correctly

closes #11023
Simon Krajewski 1 year ago
parent
commit
b4a6d43391

+ 2 - 1
src/generators/genjvm.ml

@@ -1597,7 +1597,8 @@ class texpr_to_jvm
 			end
 		| TField(e1,FStatic(c,({cf_kind = Method (MethNormal | MethInline)} as cf))) ->
 			let tl,tr = self#call_arguments cf.cf_type el in
-			jm#invokestatic c.cl_path cf.cf_name (method_sig tl tr);
+			let kind = if has_class_flag c CInterface then FKInterfaceMethod else FKMethod in
+			jm#invokestatic c.cl_path cf.cf_name ~kind (method_sig tl tr);
 			tr
 		| TField(e1,FInstance({cl_path=(["haxe";"root"],"StringBuf");cl_descendants=[]} as c,_,({cf_name="add"} as cf))) ->
 			self#texpr rvalue_any e1;

+ 2 - 2
src/generators/jvm/jvmMethod.ml

@@ -257,9 +257,9 @@ class builder jc name jsig = object(self)
 		| _ -> die "" __LOC__
 
 	(** Emits an invokestatic instruction to invoke method [name] on [path] with signature [jsigm]. **)
-	method invokestatic (path : jpath) (name : string) (jsigm : jsignature) = match jsigm with
+	method invokestatic (path : jpath) (name : string) ?(kind=FKMethod) (jsigm : jsignature) = match jsigm with
 		| TMethod(tl,tr) ->
-			let offset = code#get_pool#add_field path name jsigm FKMethod in
+			let offset = code#get_pool#add_field path name jsigm kind in
 			code#invokestatic offset tl (match tr with None -> [] | Some tr -> [tr])
 		| _ -> die "" __LOC__
 

+ 9 - 0
tests/misc/java/projects/Issue11023/Main.hx

@@ -0,0 +1,9 @@
+
+/**
+ * Main class.
+ */
+class Main {
+	public static function main():Void {
+		test.Util.testStatic();
+	}
+}

+ 15 - 0
tests/misc/java/projects/Issue11023/compile.hxml

@@ -0,0 +1,15 @@
+--cmd javac -d bin test/Util.java -g
+--cmd cd bin
+--cmd jar cf test.jar test/Util.class
+--cmd cd ..
+
+--next
+
+-cp src
+--main Main
+--java-lib bin/test.jar
+--jvm bin/main.jar
+
+--next
+
+--cmd java -jar bin/main.jar

+ 1 - 0
tests/misc/java/projects/Issue11023/compile.hxml.stdout

@@ -0,0 +1 @@
+Util.testStatic() called!

+ 7 - 0
tests/misc/java/projects/Issue11023/test/Util.java

@@ -0,0 +1,7 @@
+package test;
+
+public interface Util {
+    public static void testStatic() {
+        System.out.println("Util.testStatic() called!");
+    }
+}