groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/4] groovy git commit: GROOVY-8369: Statically compiled property access on enum class throws NoSuchFieldError (closes #625)
Date Wed, 01 Nov 2017 09:08:36 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 03bf6e6c9 -> 8c26f630a


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/950c2c22
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/950c2c22
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/950c2c22

Branch: refs/heads/GROOVY_2_5_X
Commit: 950c2c22a23f4a6432aeac639e5163dff606dbde
Parents: 03bf6e6
Author: Shil Sinha <shil.sinha@gmail.com>
Authored: Tue Oct 31 13:29:19 2017 -0400
Committer: paulk <paulk@asert.com.au>
Committed: Wed Nov 1 19:08:16 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/950c2c22/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 48e4c8c..928e791 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/950c2c22/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
+        }
+    }
 }


Mime
View raw message