Auto detect main methods inherited from Java sources (including JEP 512 ones) - #4425
Auto detect main methods inherited from Java sources (including JEP 512 ones)#4425Gedochao wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Two main things I found:
- First, not caused by this PR:
We don't check whether the main method is protected (and it's not allowed for non JEP512 Java versions). And in result:
public class Test {
protected static void main(String[] args) {
System.out.println("hello");
}
}yields:
./mill -i scala run /tmp/test-repro/Test.java --jvm 17
[...]
Error: Main method not found in class Test, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
924/925, 1 FAILED] /Users/jwarchol/Documents/GitHub/scala-cli/millw scala run /tmp/test-repro/Test.java --jvm 17 3s
I'll try to prepare a fix.
EDIT1: #4430
EDIT2: We'll probably have to make sure it works properly in inheritance too. So, imho, it'd probably be best to merge it before this PR, and address it here.
- Second, related to the changes:
package far;
public abstract class FarBase {
static void main(String[] args) {
System.out.println("FarBase.main");
}
}package near;
public abstract class NearBase extends far.FarBase {
private static void main(String[] args) {
System.out.println("NearBase.main");
}
}package near;
public class Child extends NearBase {}results in Child being incorrectly classified as a main class.
5519ecf to
8c333e6
Compare
|
Rebased on top of #4430 plus added handling for the missing case. |
warcholjakub
left a comment
There was a problem hiding this comment.
One more thing that I've overlooked previously is that when we take the example from my previous review and replace private static void main(String[] args) with public static int main(String[] args), then the same thing happens. But other than that - looks good.
Repro:
package far;
public abstract class FarBase {
static void main(String[] args) {
System.out.println("FarBase.main");
}
}package near;
public abstract class NearBase extends far.FarBase {
public static int main(String[] args) {
return 0;
}
}package near;
public class Child extends NearBase {}…12 ones) � Conflicts: � modules/build/src/main/scala/scala/build/internal/MainClass.scala
8c333e6 to
c501a28
Compare
|
Is it ready for re-review? |
actually, yep! |
Follow-up to #4418 (comment)
This enables auto-detection of main methods inherited from Java classes/interfaces. Including ones added by JEP 512.
Checklist
scala-cli fmt .)scalafix(./mill -i __.fix)How much have your relied on LLM-based tools in this contribution?
extensively
How was the solution tested?
added automated tests