You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/10/22 21:26:50 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9771: SC: private field access without revisit

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 721f46604a GROOVY-9771: SC: private field access without revisit
721f46604a is described below

commit 721f46604a55f02e0ca6b3938bbc92cdeb80d050
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Oct 22 14:23:18 2022 -0500

    GROOVY-9771: SC: private field access without revisit
---
 .../sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java | 11 ++---------
 .../groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java  | 14 ++++++++++----
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
index 91f4d4b51a..d0687442ea 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
@@ -44,7 +44,6 @@ import org.codehaus.groovy.classgen.asm.VariableSlotLoader;
 import org.codehaus.groovy.classgen.asm.WriterController;
 import org.codehaus.groovy.syntax.Token;
 import org.codehaus.groovy.syntax.TokenUtil;
-import org.codehaus.groovy.transform.sc.StaticCompilationVisitor;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -378,17 +377,11 @@ public class StaticTypesBinaryExpressionMultiTypeDispatcher extends BinaryExpres
 
         if (receiverType.isArray() && !safe && binExpWriter[getOperandType(receiverType.getComponentType())].arraySet(true)) {
             super.assignToArray(enclosing, receiver, subscript, rhsValueLoader, safe);
-        } else {
-            /*
-             * This code path is needed because ACG creates array access expressions
-             */
 
-            // GROOVY-6061
-            if (rhsValueLoader instanceof VariableSlotLoader && enclosing instanceof BinaryExpression) {
+        } else { // this code path is needed because ACG creates array access expressions
+            if (rhsValueLoader instanceof VariableSlotLoader && enclosing instanceof BinaryExpression) { // GROOVY-6061
                 rhsValueLoader.putNodeMetaData(INFERRED_TYPE, controller.getTypeChooser().resolveType(enclosing, controller.getClassNode()));
             }
-            // GROOVY-9771
-            receiver.visit(new StaticCompilationVisitor(controller.getSourceUnit(), controller.getClassNode()));
 
             // replace assignment to a subscript operator with a method call
             // e.g. x[5] = 10 -> methodCall(x, "putAt", [5, 10])
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 9e5abd0929..268b56b94f 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -360,10 +360,17 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
                 if (accessors != null) {
                     MethodNode methodNode = accessors.get(fieldName);
                     if (methodNode != null) {
-                        MethodCallExpression call = callX(receiver, methodNode.getName(), args(field.isStatic() ? nullX() : receiver));
-                        call.setImplicitThis(implicitThis);
+                        Expression thisObject;
+                        if (field.isStatic()) {
+                            thisObject = nullX();
+                        } else if (!isThisExpression(receiver)) {
+                            thisObject = receiver;
+                        } else { // GROOVY-7304, GROOVY-9771, GROOVY-9872
+                            thisObject = propX(classX(receiverType), "this");
+                        }
+
+                        MethodCallExpression call = callX(classX(receiverType), methodNode.getName(), thisObject);
                         call.setMethodTarget(methodNode);
-                        call.setSafe(safe);
                         call.visit(controller.getAcg());
                         return true;
                     }
@@ -387,7 +394,6 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
                     expr = castX(thisType, call);
                 } else {
                     expr = propX(classX(outerClass), "this");
-                    ((PropertyExpression) expr).setImplicitThis(true);
                 }
                 expr.setSourcePosition(receiver);
                 expr.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, thisType);