Scott Murphy Heiberg created GROOVY-12593:
---------------------------------------------
Summary: Assigning a static trait property named name, module,
componentType or packageName from a static trait method fails
Key: GROOVY-12593
URL: https://issues.apache.org/jira/browse/GROOVY-12593
Project: Groovy
Issue Type: Bug
Affects Versions: 5.0.8, 4.0.33, 6.0.0
Reporter: Scott Murphy Heiberg
{code:groovy}
trait T {
static String name = 'x'
static void w() { name = 'y' } // same with this.name = 'y', name += 'y',
or inside a closure or lambda
}
class C implements T {}
C.w()
assert C.name == 'y'
{code}
Actual (dynamic):
{noformat}
groovy.lang.MissingMethodException: No signature of static method:
java_lang_Object__name$set for class: C is applicable for argument types:
(String) values: [y]
{noformat}
Actual (@TypeChecked or @CompileStatic):
{noformat}
[Static type checking] - Cannot find matching method
java.lang.Class#java_lang_Object__name$set(java.lang.String) or static method
T#java_lang_Object__name$set(java.lang.String). Please check if the declared
type is correct and if the method exists.
{noformat}
Expected: the assignment sets the static property, as it does for any other
property name. The same happens for {{module}}, {{componentType}} and
{{packageName}}. Reads, and assignments from instance trait methods, work.
Cause: in a static trait method the receiver is typed as Class of T, and
{{TraitReceiverTransformer.tryGetFieldNode}} looked the field up on that type
before the trait. It found the private field of {{java.lang.Class}} with that
name, so the transformer generated a call to a setter named after {{Object}}.
Seen in 4.0.33, 5.0.8 and 6.0.0 (dynamic).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)