Scott Murphy Heiberg created GROOVY-12596:
---------------------------------------------
Summary: STC rejects "this.name" for a static accessor of a trait
in trait code ("static method of interface T can only be accessed with class
qualifier")
Key: GROOVY-12596
URL: https://issues.apache.org/jira/browse/GROOVY-12596
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 {
private static boolean flag = true
static boolean isReady() { flag }
boolean check() { this.ready }
}
class C implements T {}
assert new C().check()
{code}
Actual:
{noformat}
[Static type checking] - static method of interface T can only be accessed with
class qualifier
{noformat}
Expected: the script compiles and {{check()}} returns true, as it does in
dynamic Groovy and with the method form {{this.isReady()}}.
The same error is reported for a getX accessor ({{this.name}} for {{static
String getName()}}), inside a closure or lambda, and for {{this.cnt}} in a
static method of a sub-trait when the accessor is declared by the super trait.
Trait code compiles {{this.ready}} to a property read on the trait helper's
self parameter, which has the trait type. The check for static interface
members then treats it as an instance-qualified access to a static interface
method, although in trait code {{this}} stands for the implementing class,
which has the accessor.
6.0.0 reports the same error. 4.0.33 and 5.0.8 reject the code with "No such
property: ready for class: T".
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)