Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X d99604a51 -> ed69389a6


GROOVY-8369: Statically compiled property access on enum class throws 
NoSuchFieldError (closes #625)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/82fbec46
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/82fbec46
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/82fbec46

Branch: refs/heads/GROOVY_2_4_X
Commit: 82fbec46312a0f5b74f36b6194d7d2c425a52075
Parents: d99604a
Author: Shil Sinha <[email protected]>
Authored: Tue Oct 31 13:29:19 2017 -0400
Committer: paulk <[email protected]>
Committed: Wed Nov 1 19:09:45 2017 +1000

----------------------------------------------------------------------
 .../classgen/asm/sc/StaticTypesCallSiteWriter.java | 10 +++++-----
 .../sc/FieldsAndPropertiesStaticCompileTest.groovy | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/82fbec46/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java 
b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 1b35f4a..618066b 100644
--- 
a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ 
b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -148,11 +148,6 @@ public class StaticTypesCallSiteWriter extends 
CallSiteWriter implements Opcodes
         }
         if (makeGetPropertyWithGetter(receiver, receiverType, methodName, 
safe, implicitThis)) return;
         if (makeGetField(receiver, receiverType, methodName, safe, 
implicitThis, samePackages(receiverType.getPackageName(), 
classNode.getPackageName()))) return;
-        if (receiverType.isEnum()) {
-            mv.visitFieldInsn(GETSTATIC, 
BytecodeHelper.getClassInternalName(receiverType), methodName, 
BytecodeHelper.getTypeDescription(receiverType));
-            controller.getOperandStack().push(receiverType);
-            return;
-        }
         if (receiver instanceof ClassExpression) {
             if (makeGetField(receiver, receiver.getType(), methodName, safe, 
implicitThis, samePackages(receiver.getType().getPackageName(), 
classNode.getPackageName()))) return;
             if (makeGetPropertyWithGetter(receiver, receiver.getType(), 
methodName, safe, implicitThis)) return;
@@ -163,6 +158,11 @@ 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

http://git-wip-us.apache.org/repos/asf/groovy/blob/82fbec46/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git 
a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
 
b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
index 6af5f13..2bf0a86 100644
--- 
a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
+++ 
b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
@@ -696,4 +696,21 @@ import 
org.codehaus.groovy.transform.sc.ListOfExpressionsExpression
             assert astTrees['A$_closure1'][1].contains('INVOKESTATIC 
A.pfaccess$02 (LA;Ljava/lang/String;)Ljava/lang/String;')
         }
     }
+
+    //GROOVY-8369
+    void testPropertyAccessOnEnumClass() {
+        try {
+            assertScript '''
+                enum Foo {}
+
+                def test() {
+                    println Foo.getModifiers() // => 16401 // ENUM | FINAL | 
PUBLIC (see GROOVY_8360 wrt STATIC)
+                    println Foo.modifiers      // java.lang.NoSuchFieldError: 
modifiers
+                }    
+                test()
+            '''
+        } finally {
+            //println astTrees
+        }
+    }
 }

Reply via email to