[ 
https://issues.apache.org/jira/browse/GROOVY-12592?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135544#comment-18135544
 ] 

ASF GitHub Bot commented on GROOVY-12592:
-----------------------------------------

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.
   




> Outer.super.name() and super.name() in a closure skip the method the class 
> inherits
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-12592
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12592
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code: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'
> assert o.viaClosure() == 'root'
> {code}
> Actual: both calls return 'base'.
> Expected: both return 'root', the method Outer inherits from Root, as a super 
> call in a method of Outer does.
> A super call from a nested class or a closure does not create a super$ MOP 
> method in Outer. MetaClassImpl then takes the super$ MOP method of Root, 
> which calls Root's super method, Base.m, so Root's override is skipped. The 
> closure form is the same in 4.0.33; Outer.super is not supported there.



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

Reply via email to