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/02/05 18:49:31 UTC

[groovy] branch GROOVY-8448 created (now 058c5fe)

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

emilles pushed a change to branch GROOVY-8448
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 058c5fe  GROOVY-8448: "this.name" from anon. inner class

This branch includes the following new commits:

     new 058c5fe  GROOVY-8448: "this.name" from anon. inner class

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[groovy] 01/01: GROOVY-8448: "this.name" from anon. inner class

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 058c5fef3bb70106c47bb8a28f6290ca0e3231c7
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Feb 5 12:41:28 2022 -0600

    GROOVY-8448: "this.name" from anon. inner class
---
 .../org/codehaus/groovy/classgen/AsmClassGenerator.java   |  9 +++++++--
 src/test/gls/innerClass/InnerClassTest.groovy             | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 12f133c..11f6994 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -1180,9 +1180,14 @@ public class AsmClassGenerator extends ClassGenerator {
                         if (expression.isImplicitThis()) fieldNode = classNode.getDeclaredField(name);
                     } else {
                         fieldNode = classNode.getDeclaredField(name);
-
+                        // GROOVY-8448: "this.name" from anon. inner class
+                        if (fieldNode != null && !expression.isImplicitThis()
+                                && (fieldNode.getModifiers() & ACC_SYNTHETIC) != 0
+                                && fieldNode.getType().equals(ClassHelper.REFERENCE_TYPE)) {
+                            fieldNode = null;
+                        }
+                        // GROOVY-9501, GROOVY-9569, GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
                         if (fieldNode == null && !isFieldDirectlyAccessible(getField(classNode, name), classNode)) {
-                            // GROOVY-9501, GROOVY-9569, GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
                             if (checkStaticOuterField(expression, name)) return;
                         }
                     }
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 381caa7..2765ffc 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -52,6 +52,21 @@ final class InnerClassTest {
         '''
     }
 
+    @Test // GROOVY-8448
+    void testAccessLocalVariableVsGetterInAIC() {
+        assertScript '''
+            def x = 'local' // shared variable written as field in AIC
+            def c = new java.util.concurrent.Callable<String>() {
+                def getX() { 'getter' }
+                @Override String call() {
+                    x + ' then ' + this.x
+                }
+            }
+            String result = c()
+            assert result == 'local then getter'
+        '''
+    }
+
     @Test
     void testAccessLocalVariableFromClosureInAIC() {
         assertScript '''