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

   In a trait instance method, `TraitReceiverTransformer` rewrites a closure's 
call to a static or private trait method as `T$Trait$Helper.m($self or (Class) 
$self.getClass(), x)`. Both synthesized calls kept the default implicit-this 
flag, so static compilation resolved them against the closure's delegate:
   
   ```groovy
   @groovy.transform.CompileStatic
   trait V {
       static String who() { this.simpleName }
       def m() { new Object().with { who() } }
   }
   class E implements V {}
   assert new E().m() == 'E' // was 'Object': getDelegate().getClass()
   ```
   
   ```groovy
   class Dg { String who(Class c) { 'delegate' } }
   @groovy.transform.CompileStatic
   trait T {
       static String who() { this.simpleName }
       def m() { new Dg().with { who() } }
   }
   class C implements T {}
   assert new C().m() == 'C' // was 'delegate': Dg.who(Class) got the added 
self argument
   ```
   
   Dynamic Groovy and `@TypeChecked` return `'E'` and `'C'`.
   
   `TraitReceiverTransformer` now builds `$self.getClass()` in one place, 
`selfGetClass()`, as an explicit call on `$self`, as static field access 
already did. In a closure, the rewritten call on the trait helper is also 
explicit. Whether a delegate method of the same signature should win over a 
private or static trait method is #3138 (GROOVY-12611); the tests here use a 
delegate without such a method, so they hold either way.
   
   ## Tests
   
   These `TraitWithClosureOrLambda` tests fail without the change: 
`testInvokeTraitStaticMethodFromDelegateClosureInInstanceMethod`, 
`testInvokeSuperTraitStaticMethodFromDelegateClosureInInstanceMethod` and 
`testInvokeTraitMethodFromDelegateClosureNotOnDelegateWithSelfParameter`. They 
cover dynamic, `@TypeChecked` and `@CompileStatic` code, explicit and implicit 
`this`, a lambda, a `@Virtual` static, a super-trait static, a private method 
and two implementing classes. 
`testReadTraitStaticFieldFromDelegateClosureInInstanceMethod` covers static 
field and property access from a delegate closure. The 
`org.codehaus.groovy.transform.traitx`, `groovy.transform.stc` and 
`org.codehaus.groovy.classgen.asm.sc` tests, `groovy.ThisAndSuperTest`, and the 
`*Trait*` and `bugs` tests 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