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

ASF GitHub Bot commented on GROOVY-7797:
----------------------------------------

GitHub user blindpirate opened a pull request:

    https://github.com/apache/groovy/pull/455

    GROOVY-7797 Private trait method called from within a closure has the wrong 
"this" context

    Use helper class as method receiver instead of wrong "this" when private 
trait method in a closure is called.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/blindpirate/groovy groovy7797

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/455.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #455
    
----
commit 626e1d4734b701b3576886448cb578fc71ecc8c7
Author: zhangbo <[email protected]>
Date:   2016-11-02T05:33:32Z

    fix groovy7797 - assign correct receiver in closure

commit 824845f989cdd203c2cf3a8875167e99d1d49685
Author: zhangbo <[email protected]>
Date:   2016-11-02T05:39:06Z

    refactor to remove duplicate code

commit ac9098892b788902ba97bd3e2e6cfd88c70ae4c6
Author: zhangbo <[email protected]>
Date:   2016-11-02T05:46:33Z

    refactor a huge monster method which is over 100 lines

----


> 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)

Reply via email to