Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 9e869943c -> 225e2bfd0


Add more relevant tests for GROOVY-6171

(cherry picked from commit 7de69b5)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 225e2bfd0fd805ad5f94c4bbcb45b8d00cbfe4f8
Parents: 9e86994
Author: sunlan <sun...@apache.org>
Authored: Fri May 18 09:18:14 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri May 18 09:19:06 2018 +0800

----------------------------------------------------------------------
 src/test/groovy/bugs/Groovy6171Bug.groovy | 52 ++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/225e2bfd/src/test/groovy/bugs/Groovy6171Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy6171Bug.groovy 
b/src/test/groovy/bugs/Groovy6171Bug.groovy
index 84c0fce..abd6903 100644
--- a/src/test/groovy/bugs/Groovy6171Bug.groovy
+++ b/src/test/groovy/bugs/Groovy6171Bug.groovy
@@ -27,6 +27,32 @@ class Groovy6171Bug extends CompilableTestSupport {
         '''
     }
 
+    void testIncompatibleType1() {
+        def errMsg = shouldFail '''
+        @groovy.transform.CompileStatic
+        public class Foo<T extends List<X>, X extends Number> {
+            static void main(String[] args) {
+                def f = new Foo<ArrayList<String>, String>()
+            }
+        }
+        '''
+
+        assert errMsg.contains('The type String is not a valid substitute for 
the bounded parameter <X extends java.lang.Number>')
+    }
+
+    void testIncompatibleType2() {
+        def errMsg = shouldFail '''
+        @groovy.transform.CompileStatic
+        public class Foo<T extends List<X>, X extends Number> {
+            static void main(String[] args) {
+                def f = new Foo<HashSet<Integer>, Integer>()
+            }
+        }
+        '''
+
+        assert errMsg.contains('The type HashSet is not a valid substitute for 
the bounded parameter <T extends java.util.List<X>>')
+    }
+
     void test2() {
         assertScript '''
         @groovy.transform.CompileStatic
@@ -45,4 +71,30 @@ class Groovy6171Bug extends CompilableTestSupport {
         }
         '''
     }
+
+    void test3() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        public class Foo<T extends List<X>, X extends Number> {
+            X getFirstElement(List<X> list) {
+                X x = list.get(0)
+                
+                assert Number == x.getClass().getGenericSuperclass()
+                
+                return x
+            }
+            
+            Number getFirstNumber(T t) {
+                return getFirstElement(t)
+            }
+            
+            static void main(String[] args) {
+                def f = new Foo<ArrayList<Integer>, Integer>()
+                def list = new ArrayList<Integer>()
+                list.add(123)
+                assert 123 == f.getFirstNumber(list)
+            }
+        }
+        '''
+    }
 }

Reply via email to