Clojure

Method/Constructor resolution does not factor in widening conversion of primitive args

Details

  • Type: Enhancement Enhancement
  • Status: In Progress In Progress
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None
  • Approval:
    Vetted

Description

Problem:
When making java calls (or inlined functions), if both args and param are primitive, no widening conversion is used to locate the proper overloaded method/constructor.

Examples:

user=> (Integer. (byte 0))
java.lang.IllegalArgumentException: No matching ctor found for class java.lang.Integer (NO_SOURCE_FILE:0)
</code></pre>
The above occurs because there is no Integer(byte) constructor, though it should match on Integer(int).
<pre><code>user=> (bit-shift-left (byte 1) 1)
Reflection warning, NO_SOURCE_PATH:3 - call to shiftLeft can't be resolved.
2

In the above, a call is made via reflection to Numbers.shiftLeft(Object, Object) and its associated auto-boxing, instead of directly to the perfectly adequate Numbers.shiftLeft(long, int).

Workarounds:
Explicitly casting to the formal type.

Ancillary benefits of fixing:
It would also reduce the amount of method overloading, e.g., RT.intCast(char), intCast(byte), intCast(short), could all be removed, since such calls would pass to RT.intCast(int).

  1. clj-445-prim-conversion-update-2-patch.txt
    20/Feb/12 2:04 PM
    36 kB
    Andy Fingerhut
  2. prim-conversion.patch
    29/Apr/11 6:43 AM
    36 kB
    Alexander Taggart
  3. prim-conversion-update-1.patch
    10/May/11 3:13 PM
    36 kB
    Alexander Taggart
  4. reorg-reflector.patch
    28/Apr/11 1:19 PM
    72 kB
    Alexander Taggart

Activity

People

Vote (3)
Watch (4)

Dates

  • Created:
    Updated: