codeconsole opened a new pull request, #3118:
URL: https://github.com/apache/groovy/pull/3118
A super call made from a nested class or from a closure skips the method the
class inherits:
```groovy
class Base { String m() { 'base' } }
class Root extends Base { String m() { 'root' } }
class Outer extends Root {
class Inner { String test() { Outer.super.m() } }
String viaClosure() { def c = { -> super.m() }; c() }
}
def o = new Outer()
assert new Outer.Inner(o).test() == 'root' // returns 'base'
assert o.viaClosure() == 'root' // returns 'base'
```
A super call from a nested class or a closure does not give `Outer` a
`super$` MOP method. `MetaClassImpl` then took the `super$` MOP method of
`Root`, which calls `Root`'s super method, so `Root.m` was skipped. The closure
form behaves the same in 4.0.33, 5.0.8 and 6.0.0. `Outer.super` behaves the
same in 5.0.8 and 6.0.0; 4.0.33 does not support it.
When it looks for a MOP method for super use, the meta class now skips a MOP
method declared by the class that declares the method, or by one of its super
classes, if the receiver class inherits that method. Such a MOP method calls a
method further up the hierarchy. With no fitting MOP method, the meta class
uses the method itself.
## Tests
`InnerClassTest.testUsageOfOuterSuperMethodInherited1` to `5` and
`ThisAndSuperTest.testSuperDotMethodInClosure` (dynamic and `@TypeChecked`)
fail without the change. `testUsageOfOuterSuperMethodInherited6` and the
`@CompileStatic` case of `testSuperDotMethodInClosure` pass with and without
it: they check that an override in a subclass of `Outer` is still not called.
The `gls.*`, `groovy.lang.*`, `groovy.bugs.*`, `org.codehaus.groovy.runtime.*`,
`groovy.transform.stc.*`, `org.codehaus.groovy.classgen.asm.sc.*` and
`org.codehaus.groovy.transform.traitx.*` tests pass.
`GenericsStaticCompileTest.testSelfReferentialTypeParameter5` failed only
because a stopped run left a corrupt `@Grab` download in the local cache. 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]