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

Paul King closed GROOVY-10394.
------------------------------

> SC: operands evaluated multiple times for <=> operator on reference types
> -------------------------------------------------------------------------
>
>                 Key: GROOVY-10394
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10394
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-rc-2
>
>
> Similar to GROOVY-7473, consider the following:
> {code:groovy}
> @groovy.transform.CompileStatic
> class C {
>   int i = 0, j = 1
>   Integer getA() { i++ }
>   Integer getB() { j++ }
>   void test() {
>     assert (a <=> b) == -1
>     print i
>     print j
>   }
> }
> new C().test()
> {code}
> In cases where "a" and "b" are not identical and non-null, each is evaluated 
> 3 times (script prints "34" not "12").  This is not good if "a" and "b" are 
> expensive to compute or have side effects.
> {{BinaryExpressionTransformer}} converts {{a <=> b}} into {{a === b ? 0 : (a 
> == null ? -1 : (b == null ? 1 : a.compareTo(b)))}}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to