[
https://issues.apache.org/jira/browse/GROOVY-12825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151422#comment-18151422
]
ASF GitHub Bot commented on GROOVY-12825:
-----------------------------------------
paulk-asert commented on PR #3339:
URL: https://github.com/apache/groovy/pull/3339#issuecomment-7190667102
Thanks, Scott. This commit is included in #3362, with your authorship. #3362
adds one fix for its interaction with the GEP-33 warnings: a call whose method
reference is still pending is no longer warned about as a `Closure` value.
Closing in favour of #3362. It is also a GROOVY_6_0_X candidate, together with
#3337.
> 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)