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 2021/09/17 17:36:00 UTC

[jira] [Comment Edited] (GROOVY-10239) GroovyCastException when @CompileStatic and !in keyword are used together

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

Eric Milles edited comment on GROOVY-10239 at 9/17/21, 5:35 PM:
----------------------------------------------------------------

I also have a proposal that will provide similar static compilation for {{!in}} as you would get for {{in}} today: [https://github.com/apache/groovy/pull/1621]


was (Author: emilles):
I also have a proposal that will provide similar static compilation for `!in` as you would get for `in` today: https://github.com/apache/groovy/pull/1621

> GroovyCastException when @CompileStatic and !in keyword are used together
> -------------------------------------------------------------------------
>
>                 Key: GROOVY-10239
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10239
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 3.0.9
>         Environment: macOs Big Sur 11.5.2
> 2,6 GHz 6-Core Intel Core i7
> Java 11.0.11/16.0.1 (probably reproducible in other version)
>            Reporter: Rodolfo Yanke
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> Dear colleagues,
> I've recently updated my projects from 3.0.8 to 3.0.9 and I started getting some GroovyCastExceptions when trying to use *!in* keyword along with CompileStatic annotation:
> {code:groovy}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'Xyz'
> {code}
> We realised that it only works on 3.0.9 if we remove the CompileStatic annotation(3.0.8 works with and without).
> Here's an example of how to reproduce the exception:
> {code:groovy}
> import groovy.transform.CompileStatic
> /**
>  *  REMOVE @CompileStatic and the main method runs fine for both versions 3.0.8 and 3.0.9.
>  * 'Cannot cast object \'true\' with class \'java.lang.Boolean\' to class \'MyEnum\''
>  *  @CompileStatic only works with 3.0.8
>  */
> @CompileStatic
> class Groovy309Error {
>     static void main(String[] args) {
>         def myObj = new MyObj(status: MyEnum.A)
>         List<MyObj> items = [myObj]
>         def newItems = items.findAll { it.status !in [MyEnum.B] }
>         println newItems
>     }
> }
> enum MyEnum {
>     A, B
> }
> class MyObj {
>     MyEnum status
> }{code}
>  
> Please, forgive me if I missed something on the bug checklist but I think this ticket belongs here.
> Thank you in advance 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)