Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.7
-
None
-
Groovy 2.4.7 (tested also with 2.4.4)
Description
Static compilation fails when method is parameterized and there are varargs arguments which are not used in the call.
Error:(9, 23) Groovyc: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type Ext.
Simple classes to reproduce the problem:
public class FooInJava { //needs to be in Java, a class in Groovy works fine <T> T create(Class<T> type, Object... args) { return null; } } class Ext {} @CompileStatic class FooMain { static void main(String[] args) { Ext create = new FooInJava().create(Ext) //casting is required to make compilation pass } }
It only occurs if a class with unfortunate method signature is written in Java and static compilation is enabled. Casting to the right type helps. Originally spotted with Gradle - `ExtensionContainer.create(...)`.
Attachments
Issue Links
- links to
For what it's worth, the same problem happens with pre-compiled Groovy. The Groovy compiler is leaving the upperBounds on the generic type T as null but when loading classes, the upperBounds on T is set as java.lang.Object which then confuses the inferencing code. I haven't had time to work out exactly where we'd need to fix it yet. It might actually fix a couple of similar errors I noticed recently in slightly different contexts.