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

   A public trait static is promoted to the trait interface so `T.m()` works. 
If that static calls a `@Virtual` static, the call fails when made through the 
trait:
   
   ```groovy
   import groovy.transform.Virtual
   trait T {
       @Virtual static String setting() { 'default' }
       static String describe() { 'setting=' + setting() }
   }
   class C implements T {}
   assert C.describe() == 'setting=default'
   assert T.describe() == 'setting=default'  // MissingMethodException: No 
signature of static method: setting for class: T
   ```
   
   The interface forwarder calls the helper with the trait interface as 
`$static$self`. The `@Virtual` call site dispatches dynamically on 
`$static$self`, and `@Virtual` statics are deliberately not on the interface. 
This fails in dynamic, `@TypeChecked` and `@CompileStatic` code, including the 
`Configurable.describe()` case of the documented `@Virtual` example, and in 
6.0.0.
   
   `TraitReceiverTransformer` now emits `$static$self.isInterface() ? 
T$Trait$Helper.m($static$self, x) : $static$self.m(x)` for a `@Virtual` call 
from a static trait method. Through the trait, where there is no implementing 
class, the trait's own implementation runs. Through an implementing class, the 
dispatch is unchanged and an override still wins. The arguments are transformed 
once and shared by both branches. For a `@Virtual` static inherited from a 
super trait, the declaring trait's helper is called. Calls from instance 
methods and from closures are unchanged. The traits guide gains a callout for 
the through-the-trait call.
   
   ## Tests
   
   `VirtualAnnotationTest` adds tests for the call through the trait in 
dynamic, `@TypeChecked` and `@CompileStatic` code. They cover a `@Virtual` with 
arguments, an implementing class that overrides it, closure and lambda 
arguments, a sub-trait's promoted static, and a call from a closure. The first 
three fail without the change, as does the extended 
`TraitsSpecificationTest.testVirtualStaticDefault`. 
`org.codehaus.groovy.transform.traitx.*`, `groovy.transform.stc.*`, 
`org.codehaus.groovy.classgen.asm.sc.*`, `groovy.ThisAndSuperTest` and 
`TraitsSpecificationTest` 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