Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I have the following program
class Test { static <T> T bar(T x, T y) { return x; } static String m() { return ""; } static void main(String[] args) { Integer x = bar(m(), 1); // STC misses the error. } }
Actual behaviour
groovyc incorrectly accepts the above program, although it contains a type error at line7. This leads to the following exception at runtime:
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:179) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:251) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318) at Test.main(test.groovy:7)
Expected behaviour
The compiler should have rejected the program.
Tested against master.