You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Aaron Long (JIRA)" <ji...@apache.org> on 2016/03/21 16:17:25 UTC

[jira] [Commented] (GROOVY-7797) Private trait method called from within a closure has the wrong "this" context

    [ https://issues.apache.org/jira/browse/GROOVY-7797?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15204423#comment-15204423 ] 

Aaron Long commented on GROOVY-7797:
------------------------------------

This issue does not affect Groovy 2.4.1. It seems to have been introduced with the other breaking trait changes in 2.4.2

> Private trait method called from within a closure has the wrong "this" context
> ------------------------------------------------------------------------------
>
>                 Key: GROOVY-7797
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7797
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.6
>            Reporter: Aaron Long
>            Priority: Critical
>
> Calling a private trait method from within a closure results in a MethodMissing exception. It looks like within the closure, `this` is referring to the implementing Class and not the instance.
> This might be related to GROOVY-7373. The problem is that calling getDelegate() doesn't work as delegate also seems to have the wrong context.
> {code}
> trait MyTrait {
>     void greeter() {
>         {-> doGreeting("hi")}.call()
>     }
>     private void doGreeting(String message) { println message }  
> }
> class MyClass implements MyTrait { }
> new MyClass().greeter()
> {code}
> If you make the doGreeting method above `static`, it will work properly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)