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 3713038  GROOVY-8914: Error compiling static inner class that extends 
some other (static) inner class
3713038 is described below

commit 37130388997208141010f9e82db822aa8d8aedd7
Author: Paul King <pa...@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 {

Reply via email to