[ 
https://issues.apache.org/jira/browse/GROOVY-6644?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-6644.
--------------------------------
    Resolution: Fixed

> static methodMissing() not called if a non-existed method is invoked in a 
> closure 
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-6644
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6644
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.2.1, 2.2.2
>            Reporter: Hongliang Li
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 7.0.0-alpha-1
>
>
> Try the following code, expected foo() to trigger the static methodMissing() 
> but it doesn't.
> {code}
> class MethodMissing_not_Called {
>       static { // register a static methodMissing
>               MethodMissing_not_Called.metaClass.static.methodMissing = 
> {String name, args ->
>                       println "caught!"
>               }
>       }
>       static build(Closure c){
>               c()  // use default resolveStrategy
>       }
>       static main(args){
>               build {
>                       println "owner = $owner, delegate = $delegate"
>                       foo() // not exist
>               }
>       }
> }
> {code}
> However, if I changed foo() to this.foo(), it works.
> {code}
> class MethodMissing_Called {
>       static {
>               MethodMissing_Called.metaClass.static.methodMissing = {String 
> name, args ->
>                       println "caught!"
>               }
>       }
>       static build(Closure c){
>               c()
>       }
>       static main(args){
>               build {
>                       println "owner = $owner, delegate = $delegate"
>                       // should foo() be considered as this.foo()?
>                       this.foo()
>               }
>       }
> }
> {code}
> So when I decompiled both classes and noticed that foo() is not equal to 
> this.foo(). In the first case, foo() is compiled to
> {code}
> return acallsite1[3].callCurrent(this);
> {code}
> This explained why it looks for the closure instance.
> In the 2nd case, this.foo() is compiled to 
> {code}
> return acallsite1[3].callStatic(groovy/closure/MethodMissing_Called);
> {code}
> I know that the 'this' in closure means differently in the recent version of 
> Groovy, so I guess this 'this' should change the same?



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to