You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "XiaoboMo (JIRA)" <ji...@apache.org> on 2017/07/21 07:35:00 UTC

[jira] [Created] (GROOVY-8266) Closure to arbitrary type coercion. Call one method, but another is executed also.

XiaoboMo created GROOVY-8266:
--------------------------------

             Summary: Closure to arbitrary type coercion. Call one method, but another is executed also.
                 Key: GROOVY-8266
                 URL: https://issues.apache.org/jira/browse/GROOVY-8266
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.12
            Reporter: XiaoboMo


I have a xxx.groovy script file.

{code:java}
interface FooBar {
    int foo()

    void bar()
}

// ALL OK
// def impl =  [bar:{println 'ok'}, foo:{ 123 }] as FooBar

// `ok` is printed, which I think a bug.
def impl = { println 'ok'; 123 } as FooBar

assert impl.foo() == 123
{code}

Then I use 'groovy xxx.groovy' command to run the script. I get `ok` shown on my console.

I get the code from [http://www.groovy-lang.org/semantics.html#_closure_to_arbitrary_type_coercion]



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)