[
https://issues.apache.org/jira/browse/GROOVY-11737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18070580#comment-18070580
]
Paul King commented on GROOVY-11737:
------------------------------------
I created a PR that I believe aligns Groovy's {{main}} method selection with
JEP 445/512. I don't think Groovy's multimethod selection actually gains us
anything here, so this bypasses that. I haven't socialised this with the dev
team yet, but if you have any comments in the meantime, feel free to provide
feedback.
This is a breaking change if anyone has started using Groovy 5 with multiple
mixed static/instance main methods. In such circumstances we'd normally push
this only to Groovy 6. But given that it was an undocumented edge case, and it
would be extremely rare, and it would be horrible style, we might also backport
to 5.0.6.
> Improve clarity of Groovy main method selection priority
> --------------------------------------------------------
>
> Key: GROOVY-11737
> URL: https://issues.apache.org/jira/browse/GROOVY-11737
> Project: Groovy
> Issue Type: Question
> Reporter: Georgii Ustinov
> Assignee: Paul King
> Priority: Major
>
> Good afternoon
>
> I am currently trying to support instance main methods inside IntelliJ IDEA
> groovy plugin as a part of Groovy 5 release, however, I can’t find any
> specification of how it works.
>
> I have found that the feature was implemented here -
> [https://github.com/apache/groovy/pull/1910/files].
>
> Looking into the source code -
> [https://github.com/paulk-asert/groovy/blob/90480bfade8c20f935311055e2ceb85288870605/src/main/java/groovy/lang/GroovyShell.java#L275]
> I can see the following order:
>
> 1) static void main(String[] args);
> 2) void main(String[] args);
> 3) static void main(args);
> 4) void main(args);
> 5) static void main();
> 6) void main();
>
> The problem is that it doesn’t correspond to the reality.
>
> Let’s consider the following code main.groovy
>
>
> {code:java}
> void main(args) {
> println "1"
> }
>
> static void main() {
> println "2"
> }
> {code}
>
>
> If I run
> {code:java}
> groovy main.groovy{code}
> 1 will be printed (and it looks correct according to the semantics),
> But if I change example:
>
>
> {code:java}
> void main(String[] args) {
> println "1"
> }
>
> static void main() {
> println "2"
> }
> {code}
> 2 will be printed (and thus the order in the code is violated). But if I run
> {code:java}
> groovy main.groovy someArg{code}
> , then 1 will be printed
>
> Could you, please, provide the correct main method order resolution?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)