Repository: groovy
Updated Branches:
  refs/heads/master 8365c1555 -> 39bf95c2f


Refine resolving generics


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

Branch: refs/heads/master
Commit: 39bf95c2f13a21df2c13cf698012b2f489e693b8
Parents: 8365c15
Author: sunlan <sun...@apache.org>
Authored: Fri May 18 14:30:27 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri May 18 14:31:11 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java | 10 ++++++--
 src/test/groovy/bugs/Groovy6171Bug.groovy       | 24 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/39bf95c2/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 c3939b2..f12f65a 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -374,7 +374,7 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
 
         if (genericParameterNames.get(typeName) != null) {
             GenericsType gt = genericParameterNames.get(typeName);
-            type.setRedirect(gt.getType());
+            type.setRedirect(gt.getType()); // FIXME lost the generics type 
info
             type.setGenericsTypes(new GenericsType[]{ gt });
             type.setGenericsPlaceHolder(true);
             return true;
@@ -1490,9 +1490,15 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
             } else {
                 if (!isWild) {
                     if (toDealWithGenerics) {
+                        GenericsType originalGt = 
genericParameterNames.get(name);
                         genericParameterNames.put(name, type);
                         type.setPlaceholder(true);
-                        classNode.setRedirect(ClassHelper.OBJECT_TYPE);
+
+                        if (null == originalGt) {
+                            classNode.setRedirect(ClassHelper.OBJECT_TYPE);
+                        } else {
+                            classNode.setRedirect(originalGt.getType());
+                        }
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/39bf95c2/src/test/groovy/bugs/Groovy6171Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy6171Bug.groovy 
b/src/test/groovy/bugs/Groovy6171Bug.groovy
index abd6903..574db5b 100644
--- a/src/test/groovy/bugs/Groovy6171Bug.groovy
+++ b/src/test/groovy/bugs/Groovy6171Bug.groovy
@@ -19,6 +19,7 @@
 package groovy.bugs
 
 import gls.CompilableTestSupport
+import groovy.transform.NotYetImplemented
 
 class Groovy6171Bug extends CompilableTestSupport {
     void testGroovy6171() {
@@ -53,6 +54,7 @@ class Groovy6171Bug extends CompilableTestSupport {
         assert errMsg.contains('The type HashSet is not a valid substitute for 
the bounded parameter <T extends java.util.List<X>>')
     }
 
+    @NotYetImplemented
     void test2() {
         assertScript '''
         @groovy.transform.CompileStatic
@@ -72,6 +74,7 @@ class Groovy6171Bug extends CompilableTestSupport {
         '''
     }
 
+
     void test3() {
         assertScript '''
         @groovy.transform.CompileStatic
@@ -97,4 +100,25 @@ class Groovy6171Bug extends CompilableTestSupport {
         }
         '''
     }
+
+    void test4() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        public class Foo<T extends List<X>, X extends Number> {
+            X getFirstElement(List<X> t) {
+                X x = t.get(0)
+                return x
+            }
+            
+            static void main(String[] args) {
+                def f = new Foo<ArrayList<Integer>, Integer>()
+                def list = new ArrayList<Integer>()
+                list.add(123)
+                assert 123 == f.getFirstElement(list)
+            }
+        }
+        '''
+    }
+
+
 }

Reply via email to