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

   Under `@CompileStatic`, an instance method of `java.lang.Class` called 
without a receiver in a static method or static initializer loaded local slot 0 
as the receiver:
   
   ```groovy
   @groovy.transform.CompileStatic
   class C {
       static Object sm() { getName() }        // VerifyError: Bad local 
variable type
       static Object sp(Class t) { getName() } // returns t's name instead of 
'C'
   }
   ```
   
   Dynamic and `@TypeChecked` code call it on the class, as did 4.0.33; 5.0.8 
and 6.0.0 fail. Packed closures (`groovy.target.closure.pack`, 
`@PackedClosures`) hit the same failure: a closure in a static method is 
hoisted into a static method, so `{ -> toString() }()` there failed 
verification too. That is the failure in 
`ClosuresStaticCompileTest.testClosureObjectMethodPrecedence` under the flag.
   
   `StaticInvocationWriter.writeDirectMethodCall` now uses the enclosing class 
as the receiver when the call is in a static method, outside a closure or 
lambda class, and the method is a member of `Class`. This matches how 
`AsmClassGenerator` loads `this` in a static method. The receiver of an 
outer-class method inside `this(...)`/`super(...)` arguments is unchanged.
   
   ## Tests
   
   `MethodCallsStaticCompilationTest.testStaticContext3` (static methods, a 
static initializer, a `Class` parameter, a static nested class) and 
`PackedClosuresTransformTest.compileStaticPackedClosureInStaticMethodCallsClassMethodsOnTheClass`
 fail without the change. The packing test classes, 
`org.codehaus.groovy.classgen.asm.sc.*` and `groovy.transform.stc.*` pass, 
without and with `-Pgroovy.target.closure.pack=true` (with the flag, three 
failures remain that also fail on master and have their own issues). 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