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

   Under `@CompileStatic`, trait code that uses property syntax for a static 
accessor of the trait calls the trait interface's static forwarder, which 
passes the trait itself to the trait helper as the receiver class, so an 
accessor that reads trait state fails:
   
   ```groovy
   @groovy.transform.CompileStatic
   trait T {
       static boolean flag = true
       static boolean isReady() { flag }
       static String sm() { ready ? 'yes' : 'no' }
   }
   class C implements T {}
   assert C.sm() == 'yes' // MissingMethodException: No signature of static 
method: T__flag$get for class: T
   ```
   
   `@TypeChecked` and dynamic Groovy work, and so does the direct call 
`isReady()`, which the trait transformation turns into 
`T$Trait$Helper.isReady($static$self)`. The same failure occurs in instance 
trait methods, in closures and lambdas, for a static setter written as an 
assignment, a compound assignment or `++`/`--`, and for accessors of a super 
trait.
   
   `StaticInvocationWriter` now writes a call to a static method of a trait 
whose receiver is the trait helper's `$static$self` or `$self` parameter as a 
call to the trait helper, passing `$static$self` or `$self.getClass()` as the 
receiver class, as the method call form does. `StaticTypesCallSiteWriter` keeps 
`$static$self` as the receiver of a static getter instead of replacing it with 
the trait class, which the getter half of `cnt++` goes through. An explicit 
`T.isReady()` is not changed.
   
   ## Tests
   
   `TraitASTTransformationTest.testTraitStaticAccessorReadAsProperty`, 
`testTraitStaticAccessorWrittenAsProperty` and 
`testSuperTraitStaticAccessorAsProperty` run dynamic, `@TypeChecked` and 
`@CompileStatic`; the `@CompileStatic` variant of each fails without the 
change. The `groovy.transform.stc`, `org.codehaus.groovy.classgen.asm.sc`, 
`org.codehaus.groovy.transform.traitx` and `gls` packages and 
`groovy.ThisAndSuperTest` pass. The Checkstyle and CodeNarc gates pass.
   
   Seen in 6.0.0; 5.0.8 and 4.0.33 reject the code at compile time.
   


-- 
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