You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2019/03/05 11:18:19 UTC

[GitHub] [groovy] paulk-asert commented on issue #888: Fix assertion error for sample code

paulk-asert commented on issue #888: Fix assertion error for sample code
URL: https://github.com/apache/groovy/pull/888#issuecomment-469642834
 
 
   I don't think the original sample fails - the code comes from the test suite which is run as the documentation is produced.
   
   I can see that your example would fail though because of the static context and the default delegation strategy being OWNER_FIRST.
   
   For an instance method, the owner is the instance and there is no name property on the instance hence the delegate will be used. You can verify this by making your method an instance method:
   
   ```
   class GroovyClosure {
       static void main(args) {
           new GroovyClosure().method()
       }
       def method() {
           def p = new Person(name: 'Igor')
           def cl = { name.toUpperCase() }
           cl.delegate = p
           assert cl() == 'IGOR'
       }
   }
   
   ```
   In the static context, the class is the owner and it has a name property, hence why you are seeing the failure message.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services