codeconsole opened a new pull request, #3153:
URL: https://github.com/apache/groovy/pull/3153

   In an inner class, a property reached through the enclosing instance could 
be read from a closure, but writing it threw `MissingPropertyException` unless 
the receiver was a plain `this`:
   
   ```groovy
   class Base {
       private String z = 'outer'
       class Sub extends Base {
           def m() { { -> Sub.this.z = 'w' }(); Base.this.z }
       }
       def t() { new Sub().m() }
   }
   assert new Base().t() == 'w'   // MissingPropertyException: No such 
property: z for class: Base$Sub
   ```
   
   The same failure hit `s.z = 'w'` with `def s = this`, compound assignment 
and `++`, nested closures and lambdas, non-subclass inner classes 
(`Inner.this.z = 'w'`), and spread-dot reads and writes in a closure. Groovy 
4.0.33, 5.0.8 and 5.1.3 return `'w'`; 6.0.0 throws, since GROOVY-11823 replaced 
the generated inner-class `propertyMissing` with a metaclass fallback.
   
   A call site in a closure passes the closure class as its sender. `this.z` is 
not affected because the call site is flagged as a `this` call and the sender 
is moved out of the closure. A qualified `this` or a local variable is not 
flagged. `MetaClassImpl.getOuterProperty` and `MetaClassImpl.setOuterProperty`, 
the enclosing-instance fallback from GROOVY-11823, checked the nesting of the 
closure class and never applied. They now move the sender out to the class that 
declares the closure before checking.
   
   ## Tests
   
   `InnerClassTest.testNestedPropertyHandling8` and 
`InnerClassTest.testNestedPropertyHandling9` (dynamic and `@TypeChecked`) fail 
without the change. The `gls.*`, `bugs.*`, `groovy.lang.*`, 
`org.codehaus.groovy.runtime.*`, `org.codehaus.groovy.vmplugin.*`, 
`groovy.transform.stc.*` and `org.codehaus.groovy.classgen.asm.sc.*` tests 
pass, as do `groovy.ClosureTest` and `groovy.ThisAndSuperTest`. The Checkstyle 
and CodeNarc gates pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to