[ 
https://issues.apache.org/jira/browse/GROOVY-11496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17891064#comment-17891064
 ] 

Eric Milles commented on GROOVY-11496:
--------------------------------------

This is supported by the getAt method. The one you are getting for a list is 
this one: 
https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/List.html#getAt(java.util.Collection)

To type check, the collection would need some type arguments, like “? extends 
Number”

At this time, anything that is convertible to Number works. 

> 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
>            Priority: Minor
>
> 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)

Reply via email to