You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2018/09/25 16:37:00 UTC
[jira] [Commented] (GROOVY-7744) static import of multiple methods
with same name
[ https://issues.apache.org/jira/browse/GROOVY-7744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16627613#comment-16627613 ]
Eric Milles commented on GROOVY-7744:
-------------------------------------
Looks like the resolution is done in {{StaticImportVisitor.findStaticMethodImportFromModule}}. The method name and argument(s) expressions are available. So it may be possible to make some obvious matches, but there will remain hard-to-make choices. Static compilation adds type inference, so the expression types are available.
Is it worth exploring an enhancement to StaticImportVisitor? Or is this seen as impractical?
> static import of multiple methods with same name
> ------------------------------------------------
>
> Key: GROOVY-7744
> URL: https://issues.apache.org/jira/browse/GROOVY-7744
> Project: Groovy
> Issue Type: Improvement
> Components: groovy-jdk
> Affects Versions: 2.4.5
> Reporter: Cazacu Mihai
> Priority: Major
>
> Hi,
> Please take a look at this code:
> {code:title=test.groovy|borderStyle=solid}
> import groovy.transform.CompileStatic
> import static A1.a // as a1
> import static A2.a // as a2
> import static A3.a // as a3
> @CompileStatic
> class A1 {
> static void a(String str) { println 'a1' }
> }
> @CompileStatic
> class A2 {
> static void a(int i) { println 'a2' }
> }
> @CompileStatic
> class A3 {
> static void a(boolean b) { println 'a3' }
> }
> a("string")
> a(1)
> a(true)
> {code}
> Running it, a compile exception is thrown:
> {quote}
> Caught: groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
> Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)
> groovy.lang.MissingMethodException: No signature of method: static A3.a() is applicable for argument types: (java.lang.String) values: [string]
> Possible solutions: a(boolean), any(), any(groovy.lang.Closure), is(java.lang.Object), wait(), wait(long)
> {quote}
> It seems that the latest import overwrites the previous ones.
> Is this the expected behavior in Groovy (Java allows this syntax)?
> Best regards,
> Mihai
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)