[
https://issues.apache.org/jira/browse/GROOVY-12519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18132037#comment-18132037
]
ASF GitHub Bot commented on GROOVY-12519:
-----------------------------------------
codeconsole opened a new pull request, #3045:
URL: https://github.com/apache/groovy/pull/3045
When a class declares a static method or property with the same signature as
its superclass, `super.sm()` threw `MissingMethodException` in dynamic Groovy
and under `@TypeChecked`, or called another overload with `null`, and
`super.sp` threw `MissingPropertyException`. Under `@CompileStatic`,
`super.sm()` in a closure or lambda failed with `IncompatibleClassChangeError`.
All of them now reach the superclass's static member, as in javac. Private
static methods of the superclass stay out of reach. The same change fixes
`super.first()` in a closure or lambda of an `ArrayList` subclass under
`@CompileStatic`, which failed with `NoSuchMethodError`: an extension method is
a static method too, so it needs no `super$` helper either.
```groovy
class Base { static String sm() { 'base' } }
class Sub extends Base {
static String sm() { 'sub' }
String test() { super.sm() } // threw MissingMethodException; now 'base'
}
```
Split out of #3044.
## How
The meta-class drops a method the class declares itself from the methods
available to `super` calls, and nothing took the place of a static method that
hides one of the superclass. A `super` call now finds the hidden static method
of the nearest superclass that has one; the `super` property index is built
from the same methods, so the static property accessors resolve too. Under
`@CompileStatic`, a static target needs no `super$` helper in a closure: the
call is an `invokestatic`, valid from any class.
## Behaviour change
`super.sm()` and `super.sp` for a static member the class hides reach the
superclass's member in dynamic Groovy and under `@TypeChecked`, where they
failed or picked another overload before.
## Tests
`groovy.ThisAndSuperTest`, in all three modes, including closures and
lambdas, a static property read and written through `super`, a hidden method
two levels up, the private case, and extension methods called through `super`
from a closure and a lambda. They fail without the change. 14,938 tests in the
`groovy`, `gls`, `bugs`, `org.codehaus.groovy.classgen`, `transform`,
`runtime`, `reflection`, `vmplugin`, `control` and `ast` packages and the stub
generator tests pass, apart from `bugs.Groovy12363`, which fails on master too
when it runs after `bugs.Groovy12142` in the same JVM (#3025 fixes it). That
run predates the last commit, which only adds the extension method test;
`groovy.ThisAndSuperTest` passes with it. `groovy-contracts`,
`groovy-typecheckers`, `groovy-ginq`, `groovy-macro-library`, `groovy-json`,
`groovy-xml` and `groovy-templates` pass their tests, and every subproject
compiles its main and test sources. The Checkstyle and CodeNarc gates pass.
> super.sm() and super.sp fail for static members of the superclass (dynamic
> Groovy, and in a closure under SC)
> -------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12519
> URL: https://issues.apache.org/jira/browse/GROOVY-12519
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime, Static compilation
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> A static method or static property of the superclass reached through
> {{super}} fails in dynamic Groovy:
> {code:groovy}
> class Base {
> static String sm() { 'sm:base' }
> static String sp = 'sp:base'
> }
> class Dyn extends Base {
> static String sm() { 'sm:dyn' }
> static String sp = 'sp:dyn'
> String m() { super.sm() }
> String p() { super.sp }
> }
> new Dyn().m() // MissingMethodException: No signature of method: sm for
> class: Base
> new Dyn().p() // MissingPropertyException: No such property: sp for class: Dyn
> {code}
> The same happens inside a closure. javac accepts the equivalent Java and
> returns {{sm:base}} and {{sp:base}}. Under {{@CompileStatic}} both work in
> the class body and {{super.sp}} works in a closure, but {{super.sm()}} in a
> closure fails with {{IncompatibleClassChangeError: Expecting non-static
> method 'java.lang.String Base.sm()'}}, because the {{super$}} helper method
> calls the static method with {{invokespecial}}.
> In dynamic Groovy the super call is resolved through the {{super$}} helper
> methods of the class, which are not generated for static methods. Seen in
> 4.0.33, 5.0.8 and master.
> Expected: {{super.sm()}} and {{super.sp}} call the superclass's static method
> and read its static property, in every mode, in the class body and in
> closures and lambdas.
> PR: https://github.com/apache/groovy/pull/3044
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)