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

   Under `@CompileStatic`, `toString()`, `hashCode()`, `equals()` and 
`getClass()` called without a receiver inside a closure or lambda now go to the 
delegate or the owner according to the resolve strategy, as they do in dynamic 
and `@TypeChecked` code and as they did in 4.0. So `new StringBuilder().with { 
append('w'); toString() }` returns `'w'`, not the closure's `toString()`. In a 
lambda, `toString()` is the enclosing instance's, as in Java. In a static 
method it is the class's. Methods that `Closure` declares, such as 
`getDelegate()` or `getMetaClass()`, still resolve against the closure.
   
   The type checker looked up the methods of `Closure` before the delegate and 
the owner, and that lookup also returned the methods `Closure` inherits from 
`Object`. It now leaves those out, and the static invocation writer calls a 
method of `Object` that was resolved against the owner on the closure's this 
object, as it already did for other owner methods.
   
   A closure returned by `dehydrate()` has no this object. If it calls one of 
these methods without a receiver, it uses its own method, as before; the writer 
loads the this object and falls back to the closure when it is `null`.
   
   Tests: `ClosuresSTCTest.testClosureObjectMethodPrecedence` (also run 
statically compiled by `ClosuresStaticCompileTest`) and 
`ClosuresStaticCompileTest.testObjectMethodsInClosureWithoutThisObject`, which 
fail without the change. The `groovy`, `gls`, `bugs` and `org.codehaus.groovy` 
packages pass (15,513 tests), apart from `bugs.Groovy12363`, which also fails 
on master when it runs after `bugs.Groovy12142` in the same JVM (GROOVY-12580 
fixes it). The Checkstyle and CodeNarc gates pass.
   
   A regression in 5.0.0: 4.0.33 is correct, 5.0.8 and 6.0.0 are not.
   


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