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

Eric Milles commented on GROOVY-11558:
--------------------------------------

[~wpeers]  This issue was not disregarded.  It was investigated by 2 PMC 
members.  Clarifying details were reported and the intended change that caused 
the difference between 4.0 and prior was identified and linked.

https://github.com/apache/groovy/blame/79959041d08c57e8671feb893accca1b1b607244/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java#L352

It is a feature of the language that Closure types -- not strictly limited to 
closure syntax -- can be proxied to implement single-abstract-method types, 
including functional interfaces.

NOTE: It was my mistake that GROOVY-9881 was tagged and not GROOVY-9852.

> Method reference treated as closure in method dispatch
> ------------------------------------------------------
>
>                 Key: GROOVY-11558
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11558
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static Type Checker
>    Affects Versions: 4.0.24
>            Reporter: Wouter Peers
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: closure, dispatch, overloading
>
> When passing a method reference to an overloaded method of which one of the 
> signatures accepts a functional interface. Groovy seems to treat the method 
> ref as a closure and dispatches to the wrong method signature.
> Example:
> {code:groovy}
> @FunctionalInterface
> interface PresenceAware {
>     boolean isPresent()
> }
> class Presence {
>     static boolean isPresent(Object o){
>         o != null
>     }
>     static boolean isPresent(PresenceAware p){
>         p.isPresent()
>     }
> }
> class StringWrapper implements PresenceAware{
>     private final String s
>     StringWrapper(String s) {
>         this.s = s
>     }
>     @Override
>     boolean isPresent() {
>         return s!= null && !s.empty
>     }
> }
> assert !Presence.isPresent(null)
> assert Presence.isPresent('')
> assert !Presence.isPresent(new StringWrapper(''))
> assert Presence.isPresent(Integer.&compare) 
> // => MissingMethodException (in Groovy v4.0.24)
> assert Presence.isPresent(Integer.&valueOf) 
> // => MethodSelectionException (in Groovy v4.0.24)
> {code}
> This code runs fine in Groovy v2.4.7—as I would expect, the method references 
> passed in the last two statements are treated as an Object when dispatching 
> to Presence::isPresent mehtod.
> In Groovy v4.0.24 however the method references seem to be (wrongfully) 
> treated as closures and are dispatched to Presence::isPresent(PresenceAware) 
> signature.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to