codeconsole opened a new pull request, #3136:
URL: https://github.com/apache/groovy/pull/3136
A sub-trait refers to a public field of a super trait by its remapped name
(`T__name`, see GROOVY-11641 and GROOVY-11663). Under `@TypeChecked` and
`@CompileStatic` that worked only for a static field outside of closures:
```groovy
@groovy.transform.TypeChecked
trait T {
public static String shared = 'x'
public String f = 'i'
}
@groovy.transform.TypeChecked
trait U extends T {
static m() { def c = { T__shared }; c() } // The variable [T__shared] is
undeclared.
def n() { T__f } // No such property: T__f for
class: U
}
class C implements U {}
```
Dynamic Groovy runs both. 5.0.8 and 6.0.0 fail the same way.
`TraitReceiverTransformer` turns a dynamic variable of trait code into a
property of the trait receiver, but not inside a closure (GROOVY-8049,
GROOVY-9386). It now does so in a closure too when the name is the remapped
name of a field of a super trait. The check follows a super trait's `extends`
clause when that trait is not transformed yet.
`TraitTypeCheckingExtension.handleUnresolvedProperty` now resolves the
remapped name of an instance field of a super trait through the field helper
getter, as it already did for static fields through the static field helper. It
does this only on the instance receiver, so an instance field used in a static
method is still an error. The type is corrected through the type arguments of
the super trait.
## Tests
`TraitASTTransformationTest.testTraitAccessToInheritedStaticFieldInClosure`,
`testTraitAccessToInheritedInstanceField`,
`testTraitAccessToIndirectlyInheritedFields` and
`testTraitAccessToPrecompiledInheritedFields` run dynamic, `@TypeChecked` and
`@CompileStatic`; their `@TypeChecked` and `@CompileStatic` variants fail
without the change. `testTraitAccessToInheritedInstanceFieldInStaticContext`
checks that an instance field is still rejected in a static method. The
`groovy.transform.stc`, `org.codehaus.groovy.classgen.asm.sc`,
`org.codehaus.groovy.transform.traitx` and `gls` packages and
`groovy.ThisAndSuperTest` 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]