[
https://issues.apache.org/jira/browse/GROOVY-12605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12605:
------------------------------------------
Description:
{code:groovy}
trait T { static boolean isVr() { true } }
class C implements T { static m() { vr } }
assert C.m()
{code}
Actual: compilation fails in dynamic, type-checked and statically compiled code
alike:
{noformat}
Apparent variable 'vr' was found in a static scope but doesn't refer to a local
variable, static field or class.
{noformat}
The same happens for a static getter, for a static setter used as an assignment
target, and for a static property or accessor inherited through a super trait
(trait U extends T, class C implements U).
Expected: the bare name resolves to the static accessor woven into C, as it
does when the method is declared in a superclass and as it already does from
instance methods of C.
Cause: VariableScopeVisitor.findClassMember creates a pseudo-property for
accessor methods of the class and its superclasses, but for traits it looks
only at fields and properties, and it does not follow a super trait that is
still in the extends clause before the trait transformation. StaticVerifier
then rejects the unresolved name.
Seen in 4.0.33, 5.0.8 and 6.0.0.
PR: https://github.com/apache/groovy/pull/3132
was:
{code:groovy}
trait T { static boolean isVr() { true } }
class C implements T { static m() { vr } }
assert C.m()
{code}
Actual: compilation fails in dynamic, type-checked and statically compiled code
alike:
{noformat}
Apparent variable 'vr' was found in a static scope but doesn't refer to a local
variable, static field or class.
{noformat}
The same happens for a static getter, for a static setter used as an assignment
target, and for a static property or accessor inherited through a super trait
(trait U extends T, class C implements U).
Expected: the bare name resolves to the static accessor woven into C, as it
does when the method is declared in a superclass and as it already does from
instance methods of C.
Cause: VariableScopeVisitor.findClassMember creates a pseudo-property for
accessor methods of the class and its superclasses, but for traits it looks
only at fields and properties, and it does not follow a super trait that is
still in the extends clause before the trait transformation. StaticVerifier
then rejects the unresolved name.
Seen in 4.0.33, 5.0.8 and 6.0.0.
> A static accessor method of a trait cannot be referenced as a property from a
> static method of the implementing class
> ---------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12605
> URL: https://issues.apache.org/jira/browse/GROOVY-12605
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> trait T { static boolean isVr() { true } }
> class C implements T { static m() { vr } }
> assert C.m()
> {code}
> Actual: compilation fails in dynamic, type-checked and statically compiled
> code alike:
> {noformat}
> Apparent variable 'vr' was found in a static scope but doesn't refer to a
> local variable, static field or class.
> {noformat}
> The same happens for a static getter, for a static setter used as an
> assignment target, and for a static property or accessor inherited through a
> super trait (trait U extends T, class C implements U).
> Expected: the bare name resolves to the static accessor woven into C, as it
> does when the method is declared in a superclass and as it already does from
> instance methods of C.
> Cause: VariableScopeVisitor.findClassMember creates a pseudo-property for
> accessor methods of the class and its superclasses, but for traits it looks
> only at fields and properties, and it does not follow a super trait that is
> still in the extends clause before the trait transformation. StaticVerifier
> then rejects the unresolved name.
> Seen in 4.0.33, 5.0.8 and 6.0.0.
> PR: https://github.com/apache/groovy/pull/3132
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)