Kevin Sheppard created GROOVY-10529:
---------------------------------------

             Summary: 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


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.



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

Reply via email to