You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/09/11 15:26:00 UTC

[jira] [Comment Edited] (GROOVY-7375) Incorrect closure owner inside anonymous inner class

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

Eric Milles edited comment on GROOVY-7375 at 9/11/19 3:25 PM:
--------------------------------------------------------------

The delegate and owner seem correct within the closure "c".  Replacing "m()" with either "println owner" or "println delegate" outputs "B$1", which is the anon. inner that is assigned to the "a" property.  The resolution of the method "m" seems to be missing a check on the parent type(s) of the anon. inner class.


was (Author: emilles):
The delegate and owner seem correct within the closure "c".  Replacing "m()" with either "println owner" or "printle delegate" outputs "B$1", which is the anon. inner that is assigned to the "a" property.  The resolution of the method "m" seems to be missing a check on the parent type(s) of the anon. inner class.

> Incorrect closure owner inside anonymous inner class
> ----------------------------------------------------
>
>                 Key: GROOVY-7375
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7375
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.3
>            Reporter: Geoff Cadien
>            Priority: Major
>
> {code}
>  abstract class A {
>    private void m() {
>     println 'm'
>   }
>     
>   void wrong() {
>     m()
>     Closure c = {
>       m()
>     }
>     c()
>   }
> }
> class B {
>   A a = new A() {}
>   
>   void b() {
>    a.wrong()
>  }
> }
> def b = new B()
> b.b()
> {code}  
> Produces the following error:
> {code}
> groovy.lang.MissingMethodException: No signature of method: B.m() is applicable for argument types: () values: []
> Possible solutions: b(), is(java.lang.Object), dump(), any(), any(groovy.lang.Closure), use([Ljava.lang.Object;)
> 	at B.this$dist$invoke$1(wrong.groovy)
> 	at B$1.methodMissing(wrong.groovy)
> 	at A.invokeMethod(wrong.groovy)
> 	at A$_wrong_closure1.doCall(wrong.groovy:9)
> 	at A$_wrong_closure1.doCall(wrong.groovy)
> 	at A.wrong(wrong.groovy:12)
> 	at A$wrong.call(Unknown Source)
> 	at B.b(wrong.groovy:20)
> 	at B$b.call(Unknown Source)
> 	at wrong.run(wrong.groovy:25)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)