Unpredictable behaviour with combination of type inference and autoboxing
Java 11, Clojure 1.10.1
Fixing the reflector will also solve this CLJ-2400?
There are two underlying issues here:
The Reflector’s preference of the int signature over the long signature
The lack of a checked long → int cast in the reflector (unlike non-reflective code, which will contain a checked long → int cast)
depends on the input class, the reflector should use .getClass on the input at runtime and pick long for Long instead of doing the unchecked cast to int
What is the correct signature of Math/abs to pick if the argument expression might return any of int, long, double, etc.? I guess double?
A couple of things going on here:
1- due to the nil branch, the inferred type of the if expression is not long, so the entire if needs to go through emit instead of emitUnboxed, and the return value is thus boxed
2- the compiler can’t resolve calls to `(Math/abs x)` where the inferred type of x is not a primitive, so it compiles this to a reflective call
3- for some reason the reflector picks the `Math.abs(int)` method, truncating 5790000000 to its int value
user=> (.intValue 5790000000)
So this issue is really not about some-> :
Actionables here are:
fix the Reflector picker to pick the correct arity instead of a nonsensical one