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

ASF GitHub Bot commented on GROOVY-12825:
-----------------------------------------

paulk-asert closed pull request #3339: GROOVY-12825: SC: resolve a method 
reference in a generic call that is itself an argument from the enclosing 
parameter
URL: https://github.com/apache/groovy/pull/3339




> SC: a method reference passed to a generic call that is itself an argument is 
> rejected when only the enclosing parameter gives its type
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12825
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12825
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> import java.util.function.Function
> @groovy.transform.CompileStatic
> class C {
>     static <T> T id(T t) { t }
>     static String take(Function<String, String> f) { f.apply(' a ') }
>     static String test() {
>         take(id(String::trim))
>     }
> }
> assert C.test() == 'a'
> {code}
> With 6.0.0 and master this does not compile:
> {noformat}
> [Static type checking] - Argument is a method reference, but parameter type 
> 'T' is not a functional interface
> {noformat}
> The call id(String::trim) is an argument of take, whose parameter gives T, as 
> javac infers it. The type checker visits id(String::trim) before it chooses 
> take, so when it checks the method reference nothing gives T yet. The same 
> holds for a constructor reference, for a call that is a constructor argument, 
> and through more than one call, as in take(wrap(id(String::trim))).
> This is the case of GROOVY-12823 where the target type is the parameter of 
> the enclosing call rather than an assignment, a return or a cast. A lambda in 
> the same place is compiled as a closure and converted when it is passed, so 
> it works.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to