Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Similar to GROOVY-7473, consider the following:
@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()
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)))