codeconsole opened a new pull request, #3132:
URL: https://github.com/apache/groovy/pull/3132
A static accessor method of a trait could not be referenced as a property
from a static method of the implementing class:
```groovy
trait T { static boolean isVr() { true } }
class C implements T { static m() { vr } }
assert C.m()
```
This failed to compile in every mode, dynamic included, with "Apparent
variable 'vr' was found in a static scope but doesn't refer to a local
variable, static field or class", in 4.0.33, 5.0.8 and 6.0.0 too. The same
method declared in a superclass works, and so does the same reference from an
instance method of `C`. Static getters, static setters used as assignment
targets, and statics inherited through a super trait (`trait U extends T`)
failed the same way.
`VariableScopeVisitor.findClassMember` creates a pseudo-property for
accessor methods of the class and its superclasses. For traits it looked only
at fields and properties, and it did not follow a super trait that is still in
the `extends` clause before `TraitASTTransformation` moves it to the
interfaces. It now also matches a trait's non-private static accessor methods:
the method itself for a trait in the same compilation unit, the public static
forwarder for a precompiled trait. It also queues a trait's super trait.
Private static trait methods and static methods of plain interfaces are still
not resolved, since neither becomes a member of the implementing class. The
pseudo-property construction moved into a shared helper.
## Tests
`TraitASTTransformationTest.testTraitStaticAccessorFromStaticMethod`,
`testSuperTraitStaticAccessorFromStaticMethod` and
`testPrecompiledTraitStaticAccessorFromStaticMethod` fail without the change in
dynamic, `@TypeChecked` and `@CompileStatic` mode.
`testTraitPrivateStaticAccessorFromStaticMethod` checks that a private static
trait accessor stays rejected. `groovy.transform.stc.*`,
`org.codehaus.groovy.classgen.*` (including `asm.sc.*`),
`org.codehaus.groovy.transform.traitx.*`, `gls.*`, `bugs.*`,
`groovy.ThisAndSuperTest` and `groovy.StaticImportTest` pass. 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]