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 2022/07/29 18:48:00 UTC

[jira] [Commented] (GROOVY-10711) CompileStatic doesn't call asBoolean

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

Eric Milles commented on GROOVY-10711:
--------------------------------------

Is {{Result}} an inner class?  The {{static}} modifier makes no sense otherwise.

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