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-8914: Error compiling static inner class that extends some other (static) inner class
Date Mon, 17 Dec 2018 02:05:19 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 1feb8af  GROOVY-8914: Error compiling static inner class that extends some other
(static) inner class
1feb8af is described below

commit 1feb8aff09f90a82d217b60cb8b555f67d2469b5
Author: Paul King <paulk@asert.com.au>
AuthorDate: Mon Dec 17 12:04:54 2018 +1000

    GROOVY-8914: Error compiling static inner class that extends some other (static) inner
class
---
 .../classgen/InnerClassCompletionVisitor.java       | 11 ++++++++++-
 src/test/gls/innerClass/InnerClassTest.groovy       | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/InnerClassCompletionVisitor.java b/src/main/java/org/codehaus/groovy/classgen/InnerClassCompletionVisitor.java
index a8d84c8..4e07503 100644
--- a/src/main/java/org/codehaus/groovy/classgen/InnerClassCompletionVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/InnerClassCompletionVisitor.java
@@ -348,7 +348,7 @@ public class InnerClassCompletionVisitor extends InnerClassVisitorHelper
impleme
     private void addCompilationErrorOnCustomMethodNode(InnerClassNode node, String methodName,
Parameter[] parameters) {
         MethodNode existingMethodNode = node.getMethod(methodName, parameters);
         // if there is a user-defined methodNode, add compiler error msg and continue
-        if (existingMethodNode != null && !existingMethodNode.isSynthetic())  {
+        if (existingMethodNode != null && !isSynthetic(existingMethodNode))  {
             addError("\"" +methodName + "\" implementations are not supported on static inner
classes as " +
                     "a synthetic version of \"" + methodName + "\" is added during compilation
for the purpose " +
                     "of outer class delegation.",
@@ -356,6 +356,15 @@ public class InnerClassCompletionVisitor extends InnerClassVisitorHelper
impleme
         }
     }
 
+    // GROOVY-8914: pre-compiled classes lose synthetic boolean - TODO fix earlier as per
GROOVY-4346 then remove extra check here
+    private boolean isSynthetic(MethodNode existingMethodNode) {
+        return existingMethodNode.isSynthetic() || hasSyntheticModifier(existingMethodNode);
+    }
+
+    private boolean hasSyntheticModifier(MethodNode existingMethodNode) {
+        return (existingMethodNode.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0;
+    }
+
     private void addThisReference(ConstructorNode node) {
         if (!shouldHandleImplicitThisForInnerClass(classNode)) return;
         Statement code = node.getCode();
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 811f148..9a0d6ad 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -727,6 +727,27 @@ import org.codehaus.groovy.classgen.Verifier
             null
         '''
     }
+
+    //GROOVY-8914
+    void testNestedClassInheritingFromNestedClass() {
+        // control
+        assert new Outer8914.Nested()
+
+        assertScript '''
+            class OuterReferencingPrecompiled {
+                static class Nested extends gls.innerClass.Parent8914.Nested {}
+            }
+            assert new OuterReferencingPrecompiled.Nested()
+        '''
+    }
+}
+
+class Parent8914 {
+    static class Nested {}
+}
+
+class Outer8914 {
+    static class Nested extends Parent8914.Nested {}
 }
 
 class MyOuterClass4028 {


Mime
View raw message