Unpredictable behaviour with combination of type inference and autoboxing

Description

Environment

Java 11, Clojure 1.10.1

Activity

Show:
Enzzo Cavallo
February 12, 2020, 3:43 PM

Fixing the reflector will also solve this CLJ-2400?

 

Ghadi Shayban
July 9, 2019, 1:14 PM
Edited

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)

Nicola Mometto
July 8, 2019, 3:01 PM
Edited

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

Andy Fingerhut
July 8, 2019, 2:29 PM

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?

Nicola Mometto
July 3, 2019, 3:28 PM
Edited

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)
1495032704

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

 

Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Unassigned

Reporter

Alex Miller

Labels

Approval

Vetted

Priority

Critical