Thodoris Sotiropoulos created GROOVY-11496:
----------------------------------------------
Summary: missing type mismatch when indexing lists
Key: GROOVY-11496
URL: https://issues.apache.org/jira/browse/GROOVY-11496
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Thodoris Sotiropoulos
I have the following program
{code:java}
class Test {
public static void main(String[] args) {
List<Boolean> x = [true];
List<Boolean> y = [true];
x[y]
}
} {code}
h3. Actual behavior
The code compiles, but there's runtime error
{code:java}
Exception in thread "main"
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
object 'true' with class 'java.lang.Boolean' to class 'int'
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177)
at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.intUnbox(DefaultTypeTransformation.java:85)
at
org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(DefaultGroovyMethods.java:6195)
at Test.main(test.groovy:5) {code}
h3. Expected behavior
The code should have been rejected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)