You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by sh...@apache.org on 2017/11/01 03:31:15 UTC
groovy git commit: GROOVY-8369: Statically compiled property access
on enum class throws NoSuchFieldError (closes #625)
Repository: groovy
Updated Branches:
refs/heads/master ed884452b -> 7b5851cb9
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/7b5851cb
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7b5851cb
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7b5851cb
Branch: refs/heads/master
Commit: 7b5851cb99efc8394805dc668bf2aa34eebb42b8
Parents: ed88445
Author: Shil Sinha <sh...@gmail.com>
Authored: Tue Oct 31 13:29:19 2017 -0400
Committer: Shil Sinha <sh...@apache.org>
Committed: Tue Oct 31 23:24:15 2017 -0400
----------------------------------------------------------------------
.../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/7b5851cb/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 8d003eb..2eaa934 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/7b5851cb/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
+ }
+ }
}