Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.4
-
None
-
None
Description
Similar to GROOVY-7182, groovyc fails to handle generic types if a class uses @CompileStatic and the generically typed method has a varargs parameter. Removal of @CompileStatic or the varargs parameter eliminates the compile error.
(Clarification: methodOn need not be defined in the @CompileStatic class. In the original case, the method was ControllerLinkBuilder#methodOn from Spring's HATEOAS library.)
VarArgsGenericsCase.groovy
import groovy.transform.CompileStatic @CompileStatic class VarArgsGenericsCase { def markus(String name) { methodOn(VarArgsGenericsCase).markus(name) } static <T> T methodOn(Class<T> clazz, Object... parameters) { return clazz.newInstance() } }
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: VarArgsGenericsCase.groovy: 7: [Static type checking] - Cannot find matching method java.lang.Object#markus(java.lang.String). Please check if the declared type is correct and if the method exists. @ line 7, column 9. methodOn(VarArgsGenericsCase).markus(name) ^ 1 error
Attachments
Issue Links
- relates to
-
GROOVY-7182 Static type error when using generic methods and Closures as parameters
- Closed