codeconsole opened a new pull request, #3120:
URL: https://github.com/apache/groovy/pull/3120

   A static trait property cannot be assigned from a static trait method when 
its name matches a declared field of `java.lang.Class`: `name`, `module`, 
`componentType` or `packageName`.
   
   ```groovy
   trait T {
       static String name = 'x'
       static void w() { name = 'y' }   // or this.name = 'y', name += 'y', in 
a closure or lambda
   }
   class C implements T {}
   C.w()
   ```
   
   Dynamic Groovy throws `MissingMethodException: No signature of static 
method: java_lang_Object__name$set for class: C`. @TypeChecked and 
@CompileStatic reject the code with `Cannot find matching method 
java.lang.Class#java_lang_Object__name$set(java.lang.String)`. 4.0.33, 5.0.8 
and 6.0.0 fail the same way.
   
   In a static trait method the receiver is typed `Class<T>`. 
`TraitReceiverTransformer.tryGetFieldNode` asked that type for the field before 
it asked the trait, so it found Class's own private field, and the generated 
setter call was named after `Object`. For a `Class<T>` receiver it now looks 
only in the trait. Instance trait methods, whose receiver is the trait itself, 
are unchanged.
   
   ## Tests
   
   `TraitASTTransformationTest.testTraitStaticPropertyNamedLikeFieldOfClass` 
fails without the change in all three modes (@CompileDynamic, @TypeChecked, 
@CompileStatic). It covers each of the four names with plain, `this.`, 
compound, closure and lambda assignment from static methods, plain and `this.` 
assignment from instance methods, and assignment from a sub-trait. The 
`groovy.transform.stc.*`, `org.codehaus.groovy.classgen.asm.sc.*`, 
`org.codehaus.groovy.transform.traitx.*`, `gls.*` and `groovy.bugs.*` tests and 
`groovy.ThisAndSuperTest` pass. The Checkstyle and CodeNarc gates pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to