[ 
https://issues.apache.org/jira/browse/GROOVY-11907?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18072065#comment-18072065
 ] 

ASF GitHub Bot commented on GROOVY-11907:
-----------------------------------------

eric-milles opened a new pull request, #2451:
URL: https://github.com/apache/groovy/pull/2451

   Restructure the trait receiver transformer to funnel all the field reference 
transformation through a single method.  I replaced the `instanceof` checking 
with a simpler set of choices.
   
   1) When the self parameter is "$static$self" use directly
   2) When the field is static use "$self.getClass()"
   3) Otherwise, cast "$self" to the field helper type
   
   ```java
       private Expression transformFieldReference(final Expression exp, final 
FieldNode fn, final Expression value) {
           Expression receiver;
           if (ClassHelper.isClassType(weaved.getOriginType())) {
               receiver = varX(weaved); // $static$self
           } else if (fn.isStatic()) {
               var call = callX(varX(weaved), "getClass"); // $self.getClass()
               call.setImplicitThis(false);
               
call.setMethodTarget(ClassHelper.OBJECT_TYPE.getGetterMethod("getClass", 
false));
               receiver = call;
           } else {
               receiver = castX(fieldHelper, varX(weaved)); // (<trait 
class>$Trait$FieldHelper) $self
           }
   
           MethodCallExpression mce;
           if (value == null) {
               mce = callX(receiver, Traits.helperGetterName(fn));
           } else {
               mce = callX(receiver, Traits.helperSetterName(fn), 
transform(value));
           }
           mce.setImplicitThis(false);
           mce.setSourcePosition(exp);
   
           // GROOVY-7255: static fields are available via the implementing 
class, which is not checkable
           if (fn.isStatic()) 
mce.putNodeMetaData(TraitASTTransformation.DO_DYNAMIC, fn.getOriginType());
   
           return mce;
       }
   ```
   
   see #2443
   
   This was the error before the change:
   ```
   java.lang.AssertionError
           at groovyjarjarasm.asm.Frame.putAbstractType(Frame.java:1482)
           at 
groovyjarjarasm.asm.MethodWriter.putAbstractTypes(MethodWriter.java:1961)
           at groovyjarjarasm.asm.MethodWriter.putFrame(MethodWriter.java:1920)
           at 
groovyjarjarasm.asm.MethodWriter.visitFrameEnd(MethodWriter.java:1852)
           at groovyjarjarasm.asm.Frame.accept(Frame.java:1405)
           at 
groovyjarjarasm.asm.MethodWriter.computeAllFrames(MethodWriter.java:1630)
           at groovyjarjarasm.asm.MethodWriter.visitMaxs(MethodWriter.java:1548)
           at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:626)
           at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:110)
           at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:771)
           at 
org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1335)
           at 
org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1328)
           at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
           at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:379)
           at 
org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:780)
           at 
org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:922)
           at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:668)
           at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:642)
           at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:623)
           at 
org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:285)
   ```




> SC: trait static field helper generates invalid bytecode when method-level 
> DYNAMIC_RESOLUTION is present (GROOVY-11817 regression) 
> -----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11907
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11907
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Priority: Major
>
> This is to track the *_grails-geb testFixtures_* error discussed here:
> [Canary] Grails 8 on Groovy 5 + Spring Boot 4 integration branch
> https://github.com/apache/grails-core/pull/15557



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to