Scott Murphy Heiberg created GROOVY-12608:
---------------------------------------------

             Summary: SC calls a super trait's static accessor, read as a 
property in a closure or lambda, with the trait instead of the implementing 
class
                 Key: GROOVY-12608
                 URL: https://issues.apache.org/jira/browse/GROOVY-12608
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 6.0.0
            Reporter: Scott Murphy Heiberg


{code:groovy}
@groovy.transform.CompileStatic
trait T { private static int count = 1; static int getCnt() { count } }
@groovy.transform.CompileStatic
trait U extends T { String m() { def c = { -> cnt }; c() } }
class C implements U {}
assert new C().m() == '1'
{code}
Actual: MissingMethodException: No signature of static method: T__count$get for 
class: T is applicable for argument types: () values: []

The same happens in a lambda, in a static trait method, and for a super trait's 
static property such as static int shared = 3. Writing such a property in a 
closure (cnt = n, cnt++, s = 'y') fails to compile under @TypeChecked and 
@CompileStatic: "Cannot set read-only property: cnt".

Expected: the assertion passes, as it does in dynamic Groovy and with getCnt(). 
A delegate that has the property still comes first (p.with ... cnt).

The static compiler calls the static method on the super trait interface, which 
passes the trait itself to the trait helper as the receiver class. The type 
checker looks for setters only on the receiver type, where a static interface 
method is not inherited.

Seen on master with PR #3115 (GROOVY-12590) applied, which fixes the same call 
outside closures. 6.0.0 fails the same way.



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

Reply via email to