[ 
https://issues.apache.org/jira/browse/GROOVY-10711?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-10711:
---------------------------------
    Fix Version/s: 4.0.5
                       (was: 5.0.0-alpha-1)

> CompileStatic doesn't call asBoolean
> ------------------------------------
>
>                 Key: GROOVY-10711
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10711
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 4.0.3
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Critical
>             Fix For: 4.0.5
>
>
> This appears to be a duplicate of GROOVY-7807, but the test cases presented 
> don't quite cover the behavior I see. I have a custom record class
> {code}
> @Immutable
> @CompileStatic
> @POJO
> static class Result {
>   String channel
>   String thread
>   boolean asBoolean() {
>     println 'in asBoolean'
>     false // for debugging
>   }
> }
> {code}
> When I call this from another class that is also statically compiled, the 
> {{asBoolean}} method is not called.
> {code}
> if (!result) { // console prints diagnostic
>   throw new NoChannelException() // block is not entered
> }
> {code}
> {code}
>         12: invokeinterface #136,  3          // load the Result
>         17: astore_2
>         18: aload_2
>         19: pop
>         20: aload_2
>         21: dup
>         22: ifnonnull     30
>         25: pop
>         26: iconst_0
>         27: goto          32
>         30: pop
>         31: iconst_1
>         32: ifne          39
>         35: iconst_1
>         36: goto          40
>         39: iconst_0
>         40: ifeq          58
>         43: new           #138                // class NoChannelException
> {code}
> Both classes are in the same compilation unit, which may be relevant to the 
> behavior, as {{@CompileStatic}} seems to correctly pull in {{asBoolean}}s 
> from library code and extension method. However, in this case it's quite 
> clearly disregarding the custom method and relying solely on a null check.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to