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/04/05 18:25:03 UTC

[3/3] groovy git commit: GROOVY-8531: Fail to resolve type defined in super class written in Java

GROOVY-8531: Fail to resolve type defined in super class written in Java

(cherry picked from commit 1032854)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/67bdf0a7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/67bdf0a7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/67bdf0a7

Branch: refs/heads/GROOVY_2_4_X
Commit: 67bdf0a7acc4a7aa8d6c9cdccb621e090a4da220
Parents: 877fa82
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 00:00:50 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 02:24:56 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java | 17 ++++++++---
 .../groovy/bugs/groovy8531/Groovy8531Bug.groovy | 32 ++++++++++++++++++++
 src/test/groovy/bugs/groovy8531/Reducer.java    | 23 ++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/67bdf0a7/src/main/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/org/codehaus/groovy/control/ResolveVisitor.java
index 300416b..891e138 100644
--- a/src/main/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/org/codehaus/groovy/control/ResolveVisitor.java
@@ -273,25 +273,34 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             type.setName(name);
             if (resolve(type)) return true;
         }
-        if(resolveToNestedOfCurrent(type)) return true;
-        
+
+        // GROOVY-8531: Fail to resolve type defined in super class written in Java
+        for (ClassNode enclosingClassNode = currentClass; ClassHelper.OBJECT_TYPE != enclosingClassNode; enclosingClassNode = enclosingClassNode.getSuperClass()) {
+            if(resolveToNested(enclosingClassNode, type)) return true;
+        }
+
         type.setName(saved);
         return false;
     }
 
     private boolean resolveToNestedOfCurrent(ClassNode type) {
+        return resolveToNested(currentClass, type);
+    }
+
+    private boolean resolveToNested(ClassNode enclosingType, ClassNode type) {
         if (type instanceof ConstructedNestedClass) return false;
         // GROOVY-3110: It may be an inner enum defined by this class itself, in which case it does not need to be
         // explicitly qualified by the currentClass name
         String name = type.getName();
-        if (currentClass != type && !name.contains(".") && type.getClass().equals(ClassNode.class)) {
-            ClassNode tmp = new ConstructedNestedClass(currentClass,name);
+        if (enclosingType != type && !name.contains(".") && type.getClass().equals(ClassNode.class)) {
+            ClassNode tmp = new ConstructedNestedClass(enclosingType,name);
             if (resolve(tmp)) {
                 type.setRedirect(tmp);
                 return true;
             }
         }
         return false;
+
     }
 
     private void resolveOrFail(ClassNode type, String msg, ASTNode node) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/67bdf0a7/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy b/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
new file mode 100644
index 0000000..a8a21bc
--- /dev/null
+++ b/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy8531
+
+class Groovy8531Bug extends GroovyTestCase {
+    void test() {
+        assertScript '''
+            package groovy.bugs.groovy8531
+            class Example extends Reducer {
+                public void reduce(Context context) {}
+            }
+            
+            new Example().reduce(null)
+        '''
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/67bdf0a7/src/test/groovy/bugs/groovy8531/Reducer.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy8531/Reducer.java b/src/test/groovy/bugs/groovy8531/Reducer.java
new file mode 100644
index 0000000..7fde131
--- /dev/null
+++ b/src/test/groovy/bugs/groovy8531/Reducer.java
@@ -0,0 +1,23 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy8531;
+
+public class Reducer {
+    public abstract class Context {}
+}