You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/12/29 14:13:00 UTC
[groovy] 07/28: GROOVY-8914: Error compiling static inner class
that extends some other (static) inner class
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch refine-groovydoc
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit e96f20bd58cad609cbd23728f57386a7b605b887
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 {