groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Refine "GROOVY-8531: Fail to resolve type defined in super class written in Java"
Date Thu, 05 Apr 2018 16:52:19 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 1032854c9 -> fdaef2004


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


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

Branch: refs/heads/master
Commit: fdaef2004ab30d79c3dd7e53beddc742ba456ed2
Parents: 1032854
Author: danielsun1106 <realbluesun@hotmail.com>
Authored: Fri Apr 6 00:51:29 2018 +0800
Committer: danielsun1106 <realbluesun@hotmail.com>
Committed: Fri Apr 6 00:51:29 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/control/ResolveVisitor.java | 16 ++++++++++------
 .../groovy/bugs/groovy8531/Groovy8531Bug.groovy     |  4 ++++
 src/test/groovy/bugs/groovy8531/Reducer.java        |  4 ++++
 3 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/fdaef200/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 615af7f..a48d516 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -283,16 +283,18 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         }
 
         // 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;
-        }
+        if (resolveToNestedOfCurrentClassAndSuperClasses(type)) return true;
 
         type.setName(saved);
         return false;
     }
 
-    private boolean resolveToNestedOfCurrent(ClassNode type) {
-        return resolveToNested(currentClass, type);
+    private boolean resolveToNestedOfCurrentClassAndSuperClasses(ClassNode type) {
+        for (ClassNode enclosingClassNode = currentClass; ClassHelper.OBJECT_TYPE != enclosingClassNode;
enclosingClassNode = enclosingClassNode.getSuperClass()) {
+            if(resolveToNested(enclosingClassNode, type)) return true;
+        }
+
+        return false;
     }
 
     private boolean resolveToNested(ClassNode enclosingType, ClassNode type) {
@@ -983,7 +985,9 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                   t = new LowerCaseClass(name);
                 }
                 isClass = resolve(t);
-                if(!isClass) isClass = resolveToNestedOfCurrent(t);
+                if(!isClass) {
+                    isClass = resolveToNestedOfCurrentClassAndSuperClasses(t);
+                }
             }
             if (isClass) {
                 // the name is a type so remove it from the scoping

http://git-wip-us.apache.org/repos/asf/groovy/blob/fdaef200/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
index a8a21bc..b7ee0d2 100644
--- a/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
+++ b/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
@@ -24,9 +24,13 @@ class Groovy8531Bug extends GroovyTestCase {
             package groovy.bugs.groovy8531
             class Example extends Reducer {
                 public void reduce(Context context) {}
+                public boolean isDynamic(Type type) {
+                    return Type.DYNAMIC == type
+                }
             }
             
             new Example().reduce(null)
+            assert new Example().isDynamic(Reducer.Type.DYNAMIC)
         '''
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/fdaef200/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
index 7fde131..c9b78bf 100644
--- a/src/test/groovy/bugs/groovy8531/Reducer.java
+++ b/src/test/groovy/bugs/groovy8531/Reducer.java
@@ -20,4 +20,8 @@ package groovy.bugs.groovy8531;
 
 public class Reducer {
     public abstract class Context {}
+
+    public enum Type {
+        DYNAMIC, STATIC
+    }
 }


Mime
View raw message