[ 
https://issues.apache.org/jira/browse/GROOVY-12596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Scott Murphy Heiberg updated GROOVY-12596:
------------------------------------------
    Description: 
{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".

PR: https://github.com/apache/groovy/pull/3123

  was:
{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".


> 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: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {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".
> PR: https://github.com/apache/groovy/pull/3123



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to