Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
2.5.18, 3.0.12, 4.0.4
-
None
Description
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
@Immutable @CompileStatic @POJO static class Result { String channel String thread boolean asBoolean() { println 'in asBoolean' false // for debugging } }
When I call this from another class that is also statically compiled, the asBoolean method is not called.
if (!result) { // console prints diagnostic throw new NoChannelException() // block is not entered }
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
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.