[
https://issues.apache.org/jira/browse/GROOVY-12597?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12597:
------------------------------------------
Description:
{code:groovy}
trait T {
private static boolean flag = true
static boolean isReady() { flag }
}
class C implements T {}
assert C.isReady()
assert T.isReady()
{code}
Actual: {{T.isReady()}} (and {{T.ready}}) throws
{{groovy.lang.MissingMethodException: No signature of static method:
T__flag$get for class: T is applicable for argument types: () values: []}}. The
same happens in dynamic Groovy, with @TypeChecked and with @CompileStatic, and
for static properties, setters, closures and private static helpers.
Expected: trait static state belongs to each implementing class, so the trait
itself has none. The call should fail with an error that says so, not with a
missing internal accessor. Stateless static methods called through the trait
keep working.
Cause: the promoted interface static forwarder passes the trait class as the
static self of the helper method. A static field access in the helper becomes a
call to the generated accessor (here T__flag$get) on that class, and only
implementing classes declare one.
Seen in 6.0.0. 5.x does not promote trait statics onto the interface.
PR: https://github.com/apache/groovy/pull/3124
was:
{code:groovy}
trait T {
private static boolean flag = true
static boolean isReady() { flag }
}
class C implements T {}
assert C.isReady()
assert T.isReady()
{code}
Actual: {{T.isReady()}} (and {{T.ready}}) throws
{{groovy.lang.MissingMethodException: No signature of static method:
T__flag$get for class: T is applicable for argument types: () values: []}}. The
same happens in dynamic Groovy, with @TypeChecked and with @CompileStatic, and
for static properties, setters, closures and private static helpers.
Expected: trait static state belongs to each implementing class, so the trait
itself has none. The call should fail with an error that says so, not with a
missing internal accessor. Stateless static methods called through the trait
keep working.
Cause: the promoted interface static forwarder passes the trait class as the
static self of the helper method. A static field access in the helper becomes a
call to the generated accessor (here T__flag$get) on that class, and only
implementing classes declare one.
Seen in 6.0.0. 5.x does not promote trait statics onto the interface.
> Calling a stateful trait static method through the trait fails with
> MissingMethodException for the internal field accessor
> --------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12597
> URL: https://issues.apache.org/jira/browse/GROOVY-12597
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> trait T {
> private static boolean flag = true
> static boolean isReady() { flag }
> }
> class C implements T {}
> assert C.isReady()
> assert T.isReady()
> {code}
> Actual: {{T.isReady()}} (and {{T.ready}}) throws
> {{groovy.lang.MissingMethodException: No signature of static method:
> T__flag$get for class: T is applicable for argument types: () values: []}}.
> The same happens in dynamic Groovy, with @TypeChecked and with
> @CompileStatic, and for static properties, setters, closures and private
> static helpers.
> Expected: trait static state belongs to each implementing class, so the trait
> itself has none. The call should fail with an error that says so, not with a
> missing internal accessor. Stateless static methods called through the trait
> keep working.
> Cause: the promoted interface static forwarder passes the trait class as the
> static self of the helper method. A static field access in the helper becomes
> a call to the generated accessor (here T__flag$get) on that class, and only
> implementing classes declare one.
> Seen in 6.0.0. 5.x does not promote trait statics onto the interface.
> PR: https://github.com/apache/groovy/pull/3124
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)