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:48:19 UTC

[groovy] branch GROOVY_2_5_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_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 2efc2c2  GROOVY-9642: resolve anon. inner base type in same scope as ctor call (closes #1313)
2efc2c2 is described below

commit 2efc2c2b5e851b41a1df3996350174804b89116a
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 86e5675..6cb648a 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1244,9 +1244,13 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
 
     protected Expression transformConstructorCallExpression(ConstructorCallExpression 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 b09556f..5d061e1 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -990,6 +990,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 '''