You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2024/11/13 13:46:00 UTC

[jira] [Commented] (GROOVY-11496) missing type mismatch when indexing lists

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

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

The signature of getAt cannot be changed to {{getAt(List<T> self, Collection<? extends Number> indices)}} without dropping support for nested collections.  Presently, you can do: {{list.getAt([1,[2,3],4])}}

> 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)