Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
I have the following program
class A<T> { T x; A(T x) {this.x = x;} A() {} } class B<T extends Object> extends A<T> { B(T x) { super(x); } B() {} T m() { A<T> x = new B<Object>("fd"); // Misses type error: B<Object> is not a subtype of A<T> return x.x; } } class Test { public static void main(String[] args) { Integer x = new B<Integer>().m(); } }
Actual behavior
The above program contains a type error, but the compilers misses it. As a result, a ClassCastException happens at runtime:
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'fd' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:180) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:295) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:252) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318) at Test.main(test.groovy:25)
Expected behaviour
The compiler should not have type checked the assignment at line 17 and have produced an error message of the form: B<Object> cannot be converted into A<T>.
Tested against master (commit: ee12bb52381e8f0583c61fc25d43de1f55b80a87)