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 2022/06/09 18:05:00 UTC

[jira] [Resolved] (GROOVY-10653) SC: support extension or variadic method reference with instance expression

     [ https://issues.apache.org/jira/browse/GROOVY-10653?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-10653.
----------------------------------
    Fix Version/s: 5.0.0-alpha-1
       Resolution: Fixed

https://github.com/apache/groovy/commit/a0f45182d36850ed13cdc27f3feeadc4ecdc6b1d

> SC: support extension or variadic method reference with instance expression
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-10653
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10653
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.0-alpha-1
>
>
> Case #1:
> {code:groovy}
> @CompileStatic
> int test(CharSequence chars) {
>     IntSupplier sizing = chars::size // from StringGroovyMethods
>     return sizing.getAsInt()
> }
> {code}
> "size" is extension method (static method from another class).  Currently this errors at runtime: Incorrect number of parameters for static method invokeStatic org.codehaus.groovy.runtime.StringGroovyMethods.size:(CharSequence)int; 0 captured parameters, 0 functional interface method parameters, 1 implementation parameters
> Case #2:
> {code:groovy}
> class C {
>     List m(... args) {
>         [this,*args]
>     }
> }
> @CompileStatic
> void test(C c) {
>     BiFunction<Integer, Integer, List> two = c::m
>     def list = two.apply(1,2)
>     assert list.size() == 3
>     assert list[0] == c
>     assert list[1] == 1
>     assert list[2] == 2
> }
> test(new C())
> {code}
> "m" requires an adapter method (in the enclosing script class), which results in a static method in a different class from that of "c".



--
This message was sent by Atlassian Jira
(v8.20.7#820007)