codeconsole opened a new pull request, #3088:
URL: https://github.com/apache/groovy/pull/3088
Under `@CompileStatic`, `a <=> b` called the compare method of the wrapper
of the left operand's type whenever the right operand had a primitive type, not
only when both had the same primitive type: the condition read "same type and
primitive left, or primitive right".
```groovy
@CompileStatic
class C {
static int wide(int x, long y) { x <=> y } // 0 <=> 4294967296L gave 0
static int frac(int x, double y) { x <=> y } // 1 <=> 1.5d gave 0
static int nul(Integer x, int y) { x <=> y } // null <=> 1 threw
NullPointerException
}
```
A left operand of a type without a compare method, such as `BigDecimal`, a
type parameter or `Number`, crashed the compiler with an
IndexOutOfBoundsException, which also hit `a <=> b >= 0` (it parses as `a <=>
(b >= 0)`). Only operands of the same primitive type now use the wrapper's
compare method; any other pair is compared as in dynamic Groovy.
## Tests
`STCnAryExpressionTest.testSpaceshipOperatorWithPrimitiveRightOperand`, also
run statically compiled, fails without the change. 11,626 tests in the
`groovy`, `gls`, `bugs` and STC/SC packages pass, apart from a `@Grab` test
that passes on rerun. The Checkstyle and CodeNarc gates pass.
Seen in 4.0.33, 5.0.8 and 6.0.0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]