groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch master updated: GROOVY-9007: Also handle private Enum field access within Closures
Date Mon, 06 May 2019 15:24:15 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 7132379  GROOVY-9007: Also handle private Enum field access within Closures
7132379 is described below

commit 713237951fe31981047f204da7e69e7138c9b159
Author: Paul King <paulk@asert.com.au>
AuthorDate: Tue May 7 01:24:01 2019 +1000

    GROOVY-9007: Also handle private Enum field access within Closures
---
 .../classgen/asm/sc/StaticTypesCallSiteWriter.java     |  5 -----
 src/test/groovy/bugs/Groovy9007Bug.groovy              | 18 +++++++++++++++++-
 2 files changed, 17 insertions(+), 6 deletions(-)

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 23707ef..05a28e3 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
@@ -203,11 +203,6 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements
Opcodes
             if (makeGetPropertyWithGetter(receiver, CLASS_Type, methodName, safe, implicitThis))
return;
             if (makeGetField(receiver, CLASS_Type, methodName, safe, false, true)) return;
         }
-        if (receiverType.isEnum()) {
-            mv.visitFieldInsn(GETSTATIC, BytecodeHelper.getClassInternalName(receiverType),
methodName, BytecodeHelper.getTypeDescription(receiverType));
-            controller.getOperandStack().push(receiverType);
-            return;
-        }
         if (makeGetPrivateFieldWithBridgeMethod(receiver, receiverType, methodName, safe,
implicitThis)) return;
 
         // GROOVY-5580, it is still possible that we're calling a superinterface property
diff --git a/src/test/groovy/bugs/Groovy9007Bug.groovy b/src/test/groovy/bugs/Groovy9007Bug.groovy
index a30a708..a75e452 100644
--- a/src/test/groovy/bugs/Groovy9007Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9007Bug.groovy
@@ -19,7 +19,7 @@
 package groovy.bugs
 
 class Groovy9007Bug extends GroovyTestCase {
-    void testProtectedFieldInEnum() {
+    void testProtectedFieldInClosureInEnum() {
         assertScript '''
             @groovy.transform.CompileStatic
             enum E {
@@ -35,6 +35,22 @@ class Groovy9007Bug extends GroovyTestCase {
         '''
     }
 
+    void testPrivateFieldInClosureInEnum() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            enum E {
+                ONE(1), TWO(2)
+                private final int n
+                E(int n) { this.n = n }
+                static E valueOf(int n) {
+                    values().find { it.n == n }
+                }
+            }
+
+            assert E.valueOf(2).name() == 'TWO'
+        '''
+    }
+
     // GROOVY-8978
     void testProtectedFieldInChildWithExplicitThis() {
         assertScript '''


Mime
View raw message