groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8737) STC Method resolution fails if other methods with more parameters exist
Date Thu, 09 Aug 2018 11:15:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16574703#comment-16574703
] 

Paul King commented on GROOVY-8737:
-----------------------------------

Groovy allows you to use an array to indicate varargs. It's something from JDK 1.4 days in
fact but has so far always been kept for backwards compatibility. And with varargs you can
have no supplied args hence they fall back to the same signature.

> STC Method resolution fails if other methods with more parameters exist
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-8737
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8737
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.15, 3.0.0-alpha-3, 2.5.1
>         Environment: Ubuntu 18.04, Java 8u181
>            Reporter: Patric Bechtel
>            Priority: Major
>
> Given two classes as follows
> {code:java}
> @groovy.transform.CompileStatic
> class A {
>    public static String msg( String key, Object[] args ) { "key=$key, args=$args" }
>    public static String msg( String key, Object[] args, Object[] parts ) { "key=$key,
args=$args, parts=$parts" }
>    public static String msg( String key, Object[] args, String[] names ) { "key=$key,
args=$args, names=$names" }
> }
> {code}
> and
> {code:java}
> @groovy.transform.CompileStatic
> public class B {
>    public static void main( String[] args ) {
>       println A.msg( 'hello', [ 'world' ] as Object[] )
>    }
> }
> {code}
> will not compile with the error
> {noformat}
> B.groovy: 4: [Static type checking] - Reference to method is ambiguous. Cannot choose
between [java.lang.String A#msg(java.lang.String, java.lang.Object[], java.lang.Object[]),
java.lang.String A#msg(java.lang.String, java.lang.Object[], java.lang.String[])]
>  @ line 4, column 15.
>          println A.msg( 'hello', [ 'world' ] as Object[] )
> {noformat}
> Though there's a perfect match for the called method, it tries to choose one of the longer
signatures.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message