You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/07/18 09:47:35 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9642: resolve anon. inner base type in same scope as ctor call (closes #1313)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new a684e0e  GROOVY-9642: resolve anon. inner base type in same scope as ctor call (closes #1313)
a684e0e is described below

commit a684e0e8f07ae09498d762c7f40857ca0090fbbe
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Jul 13 17:30:55 2020 -0500

    GROOVY-9642: resolve anon. inner base type in same scope as ctor call (closes #1313)
---
 .../org/codehaus/groovy/control/ResolveVisitor.java  | 10 +++++++---
 src/test/gls/innerClass/InnerClassTest.groovy        | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 4395dc8..f42e862 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1240,9 +1240,13 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         findPossibleOuterClassNodeForNonStaticInnerClassInstantiation(cce);
 
         ClassNode type = cce.getType();
-        resolveOrFail(type, cce);
-        if (Modifier.isAbstract(type.getModifiers())) {
-            addError("You cannot create an instance from the abstract " + getDescription(type) + ".", cce);
+        if (cce.isUsingAnonymousInnerClass()) { // GROOVY-9642
+            resolveOrFail(type.getUnresolvedSuperClass(false), type);
+        } else {
+            resolveOrFail(type, cce);
+            if (type.isAbstract()) {
+                addError("You cannot create an instance from the abstract " + getDescription(type) + ".", cce);
+            }
         }
 
         return cce.transformExpression(this);
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 81e51d9..1d4c1ad 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -1216,6 +1216,26 @@ final class InnerClassTest {
         '''
     }
 
+    @Test // GROOVY-9642
+    void testResolveInnerOfSuperType9() {
+        assertScript '''
+            class C {
+                interface I {}
+                static class T {}
+            }
+            class D extends C {
+                static I one() {
+                    new I() {}
+                }
+                static T two() {
+                    new T() {}
+                }
+            }
+            assert D.one() instanceof C.I
+            assert D.two() instanceof C.T
+        '''
+    }
+
     @Test // GROOVY-5679, GROOVY-5681
     void testEnclosingMethodIsSet() {
         assertScript '''