Skip to content

Instantly share code, notes, and snippets.

@mperry
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mperry/11285137 to your computer and use it in GitHub Desktop.
Save mperry/11285137 to your computer and use it in GitHub Desktop.
Static methods do not type check generic parameters properly
// defect in Groovy 2.3.0-rc-1, code does not compile when it should
// run with: groovy staticMethodTypeChecking.groovy
// http://jira.codehaus.org/browse/GROOVY-6723
/*
Output is (note that line numbers will not match):
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
D:\repositories\functionalgroovy\consume\scripts\staticMethodTypeChecking.groovy:
14: [Static type checking] - Cannot call <A,B> Test1#pair1(A, B) with arguments
[A, A]
@ line 14, column 9.
pair1(a, a)
^
D:\repositories\functionalgroovy\consume\scripts\staticMethodTypeChecking.groovy:
22: [Static type checking] - Cannot call <A> Test1#list1(A) with arguments [B]
@ line 22, column 9.
list1(b)
^
2 errors
*/
import groovy.transform.TypeChecked
@TypeChecked
class Test1 {
static <A, B> void pair1(A a, B b) {
}
static <A, B> void pair2(A a, B b) {
pair1(a, a)
}
static <A> List<A> list1(A a) {
[a]
}
static <B> List<B> list2(B b) {
list1(b)
}
static <A> List<A> list3(A a) {
list1(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment