groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-8531: Fail to resolve type defined in super class written in Java
Date Thu, 05 Apr 2018 16:33:22 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 5d47b5948 -> 27ae026b0


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/27ae026b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/27ae026b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/27ae026b

Branch: refs/heads/GROOVY_2_5_X
Commit: 27ae026b03de91c82e3079e88f5f962d4a702a92
Parents: 5d47b59
Author: danielsun1106 <realbluesun@hotmail.com>
Authored: Fri Apr 6 00:00:50 2018 +0800
Committer: danielsun1106 <realbluesun@hotmail.com>
Committed: Fri Apr 6 00:33:16 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/27ae026b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index a06ad99..615af7f 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -281,25 +281,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/27ae026b/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/27ae026b/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 {}
+}


Mime
View raw message