groovy git commit: Add more relevant tests for GROOVY-6171
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X ea98b063f -> 0bfe45357 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/0bfe4535 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0bfe4535 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0bfe4535 Branch: refs/heads/GROOVY_2_5_X Commit: 0bfe45357e8e621f6eb93882e278fdab1c955d2c Parents: ea98b06 Author: sunlan Authored: Fri May 18 09:18:14 2018 +0800 Committer: sunlan Committed: Fri May 18 09:19:45 2018 +0800 -- src/test/groovy/bugs/Groovy6171Bug.groovy | 52 ++ 1 file changed, 52 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/0bfe4535/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, X extends Number> { +static void main(String[] args) { +def f = new Foo, String>() +} +} +''' + +assert errMsg.contains('The type String is not a valid substitute for the bounded parameter ') +} + +void testIncompatibleType2() { +def errMsg = shouldFail ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +static void main(String[] args) { +def f = new Foo, Integer>() +} +} +''' + +assert errMsg.contains('The type HashSet is not a valid substitute for the bounded parameter >') +} + void test2() { assertScript ''' @groovy.transform.CompileStatic @@ -45,4 +71,30 @@ class Groovy6171Bug extends CompilableTestSupport { } ''' } + +void test3() { +assertScript ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +X getFirstElement(List 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, Integer>() +def list = new ArrayList() +list.add(123) +assert 123 == f.getFirstNumber(list) +} +} +''' +} }
groovy git commit: Add more relevant tests for GROOVY-6171
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 Authored: Fri May 18 09:18:14 2018 +0800 Committer: sunlan 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, X extends Number> { +static void main(String[] args) { +def f = new Foo, String>() +} +} +''' + +assert errMsg.contains('The type String is not a valid substitute for the bounded parameter ') +} + +void testIncompatibleType2() { +def errMsg = shouldFail ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +static void main(String[] args) { +def f = new Foo, Integer>() +} +} +''' + +assert errMsg.contains('The type HashSet is not a valid substitute for the bounded parameter >') +} + void test2() { assertScript ''' @groovy.transform.CompileStatic @@ -45,4 +71,30 @@ class Groovy6171Bug extends CompilableTestSupport { } ''' } + +void test3() { +assertScript ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +X getFirstElement(List 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, Integer>() +def list = new ArrayList() +list.add(123) +assert 123 == f.getFirstNumber(list) +} +} +''' +} }
groovy git commit: Add more relevant tests for GROOVY-6171
Repository: groovy Updated Branches: refs/heads/master ff8d74741 -> 7de69b55d Add more relevant tests for GROOVY-6171 Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7de69b55 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7de69b55 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7de69b55 Branch: refs/heads/master Commit: 7de69b55d396aec343f8affdbe662ab4a5d7960c Parents: ff8d747 Author: sunlan Authored: Fri May 18 09:18:14 2018 +0800 Committer: sunlan Committed: Fri May 18 09:18:27 2018 +0800 -- src/test/groovy/bugs/Groovy6171Bug.groovy | 52 ++ 1 file changed, 52 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/7de69b55/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, X extends Number> { +static void main(String[] args) { +def f = new Foo, String>() +} +} +''' + +assert errMsg.contains('The type String is not a valid substitute for the bounded parameter ') +} + +void testIncompatibleType2() { +def errMsg = shouldFail ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +static void main(String[] args) { +def f = new Foo, Integer>() +} +} +''' + +assert errMsg.contains('The type HashSet is not a valid substitute for the bounded parameter >') +} + void test2() { assertScript ''' @groovy.transform.CompileStatic @@ -45,4 +71,30 @@ class Groovy6171Bug extends CompilableTestSupport { } ''' } + +void test3() { +assertScript ''' +@groovy.transform.CompileStatic +public class Foo, X extends Number> { +X getFirstElement(List 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, Integer>() +def list = new ArrayList() +list.add(123) +assert 123 == f.getFirstNumber(list) +} +} +''' +} }