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

Kevin Sheppard updated GROOVY-10529:
------------------------------------
    Description: 
When I run the following code:
{code:groovy}
interface Handler {
    void handle(String)
}

def foo(Handler... handlers) {
    handlers.each { it.handle('Hello!') }
}

foo({ print(it) }, { print(it.toUpperCase()) }) {code}
I get this error message:
{noformat}
No signature of method: ConsoleScript8.foo() is applicable for argument types: 
(ConsoleScript8$_run_closure1, ConsoleScript8$_run_closure2) values:    
[ConsoleScript8$_run_closure1@4359df7, ConsoleScript8$_run_closure2@4288c46b]
{noformat}
Apparently, Groovy isn't seeing the closures as instances of Handler. This 
doesn't happen in Java or Kotlin.

The workaround is to cast each closure as a Handler instance, but it makes for 
very awkward usage of the method.
{code:java}
foo({ print(it) } as Handler, { print(it.toUpperCase()) } as Handler)  {code}

  was:
When I run the following code:

{code:groovy}
interface Handler {
    void handle(String)
}

def foo(Handler... handlers) {
    handlers.each { it.handle('Hello!') }
}

foo({ print(it) }, { print(it.toUpperCase()) }) {code}

I get this error message:

{noformat}
No signature of method: ConsoleScript8.foo() is applicable for argument types: 
(ConsoleScript8$_run_closure1, ConsoleScript8$_run_closure2) values:    
[ConsoleScript8$_run_closure1@4359df7, ConsoleScript8$_run_closure2@4288c46b]
{noformat}

Apparently, Groovy isn't seeing the closures as instances of Handler. This 
doesn't happen in Java or Kotlin.


> Cannot use closures as arguments for varargs method
> ---------------------------------------------------
>
>                 Key: GROOVY-10529
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10529
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.0.10
>         Environment: Edition  Windows 10 Enterprise
> Version       20H2
> Installed on  ‎10/‎12/‎2020
> OS build      19042.685
> Experience    Windows Feature Experience Pack 120.2212.551.0
>            Reporter: Kevin Sheppard
>            Priority: Minor
>
> When I run the following code:
> {code:groovy}
> interface Handler {
>     void handle(String)
> }
> def foo(Handler... handlers) {
>     handlers.each { it.handle('Hello!') }
> }
> foo({ print(it) }, { print(it.toUpperCase()) }) {code}
> I get this error message:
> {noformat}
> No signature of method: ConsoleScript8.foo() is applicable for argument 
> types: (ConsoleScript8$_run_closure1, ConsoleScript8$_run_closure2) values:   
>  [ConsoleScript8$_run_closure1@4359df7, ConsoleScript8$_run_closure2@4288c46b]
> {noformat}
> Apparently, Groovy isn't seeing the closures as instances of Handler. This 
> doesn't happen in Java or Kotlin.
> The workaround is to cast each closure as a Handler instance, but it makes 
> for very awkward usage of the method.
> {code:java}
> foo({ print(it) } as Handler, { print(it.toUpperCase()) } as Handler)  {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to