You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/05/06 15:29:36 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-9007: Also handle
private Enum field access within Closures
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 6535ee7 GROOVY-9007: Also handle private Enum field access within Closures
6535ee7 is described below
commit 6535ee77488fb84a6ec0b687ecb21801b20e1282
Author: Paul King <pa...@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 0e46448..196e5e0 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 '''