Skip to content

Commit

Permalink
[jvm] refer to static instance methods correctly
Browse files Browse the repository at this point in the history
closes #11023
  • Loading branch information
Simn committed Oct 14, 2023
1 parent c612905 commit b4a6d43
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/generators/genjvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/generators/jvm/jvmMethod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
9 changes: 9 additions & 0 deletions tests/misc/java/projects/Issue11023/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/**
* Main class.
*/
class Main {
public static function main():Void {
test.Util.testStatic();
}
}
15 changes: 15 additions & 0 deletions tests/misc/java/projects/Issue11023/compile.hxml
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tests/misc/java/projects/Issue11023/compile.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Util.testStatic() called!
7 changes: 7 additions & 0 deletions tests/misc/java/projects/Issue11023/test/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test;

public interface Util {
public static void testStatic() {
System.out.println("Util.testStatic() called!");
}
}

4 comments on commit b4a6d43

@kLabz
Copy link
Contributor

@kLabz kLabz commented on b4a6d43 Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like only linux is ok with this test :/

@Simn
Copy link
Member Author

@Simn Simn commented on b4a6d43 Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I copied it from https://github.com/HaxeFoundation/haxe/tree/development/tests/misc/java/projects/Issue9574, but there's a bin directory there. Could you try adding it like here?

@kLabz
Copy link
Contributor

@kLabz kLabz commented on b4a6d43 Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :)
Still sounds a bit weird that other platforms need the bin directory to exist, though 🤔

@Simn
Copy link
Member Author

@Simn Simn commented on b4a6d43 Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it either...

Please sign in to comment.