Scott Murphy Heiberg created GROOVY-12609:
---------------------------------------------
Summary: STC rejects the remapped name of a super trait field in a
closure or for an instance field ("The variable [T__x] is undeclared" / "No
such property: T__x")
Key: GROOVY-12609
URL: https://issues.apache.org/jira/browse/GROOVY-12609
Project: Groovy
Issue Type: Bug
Affects Versions: 5.0.8, 4.0.33, 6.0.0
Reporter: Scott Murphy Heiberg
{code:groovy}
@groovy.transform.TypeChecked // or @CompileStatic
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() }
def n() { T__f }
}
class C implements U {}
assert C.m() == 'x'
assert new C().n() == 'i'
{code}
Actual: compilation fails with "[Static type checking] - The variable
[T__shared] is undeclared." and "[Static type checking] - No such property:
T__f for class: U". The same happens for writes, lambdas, an instance field in
a closure, and a precompiled super trait.
Expected: both compile and return x and i, as they do in dynamic Groovy. The
remapped name is the documented way to use a super trait's field (GROOVY-11641,
GROOVY-11663).
The trait transformation leaves a dynamic variable in a closure as it is, so
the GROOVY-11663 handling of the remapped name on the trait receiver never sees
it. That handling also only looks for static field getters.
Seen in 5.0.8 and 6.0.0; 4.0.33 reports the closure case the same way.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)