Thodoris Sotiropoulos created GROOVY-11382:
----------------------------------------------
Summary: fail to identify type error in static array
initialization with generic classes
Key: GROOVY-11382
URL: https://issues.apache.org/jira/browse/GROOVY-11382
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Thodoris Sotiropoulos
Probably related to GROOVY-9985
{code:java}
import java.util.*
class Test {
public static void main(String[] args) {
List<String> lst = ["fda"];
List<Integer>[] x = new List<Integer>[]{lst};
Integer k = x[0].get(0)
}
} {code}
h3. Actual behavior
The program compiles but receiving the following runtime error:
{code:java}
Exception in thread "main"
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
object 'fda' with class 'java.lang.String' to class 'java.lang.Integer'
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:173)
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:288)
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:245)
at
org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
at Test.main(test.groovy:7) {code}
h3. Expected behavior
The program should have been rejected
--
This message was sent by Atlassian Jira
(v8.20.10#820010)