Clojure

Hinting the arg vector of a primitive-taking fn with a non-primitive type results in AbstractMethodError when invoked

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.3
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Hinting the arg vector of a primitive-taking fn with a non-primitive type results in AbstractMethodError when invoked.

user=> (defn f1 ^String [^String s] s)
#'user/f1
user=> (f1 "foo")
"foo"
user=> (defn f2 ^long [^String s ^long i] i)
#'user/f2
user=> (f2 "foo" 1)
1
user=> (defn f3 ^String [^String s ^long i] s)                                       
#'user/f3
user=> (f3 "foo" 1)
AbstractMethodError user$f3.invokePrim(Ljava/lang/Object;J)Ljava/lang/Object;  user/eval8 (NO_SOURCE_FILE:6)

Solution: Add check to emit invokePrim with return type of double or long if appropriate, otherwise do prior behavior of emitting return type of Object.

Patch: The {{CLJ-850-conform-to-invokePrim.diff}} patch is constructed per Rich's feedback, and appears good to me [Stu].

  1. CLJ-850.patch
    18/Oct/11 2:54 PM
    2 kB
    Ben Smith-Mannschott
  2. CLJ-850-conform-to-invokePrim.diff
    19/Dec/12 3:41 PM
    2 kB
    Ghadi Shayban
  3. CLJ-850-test.patch
    15/Oct/11 11:54 AM
    2 kB
    Ben Smith-Mannschott
  4. clj-850-type-hinted-fn-abstractmethoderror-patch4.txt
    01/Nov/12 7:22 PM
    4 kB
    Andy Fingerhut

Activity

Alexander Taggart made changes -
Field Original Value New Value
Summary Hinting the arg vector of a primitive-taking fn with a non-primitive type results in AbstractMethodError Hinting the arg vector of a primitive-taking fn with a non-primitive type results in AbstractMethodError when invoked
Ben Smith-Mannschott made changes -
Attachment CLJ-850-test.patch [ 10400 ]
Ben Smith-Mannschott made changes -
Attachment CLJ-850.patch [ 10411 ]
Ben Smith-Mannschott made changes -
Patch Code and Test [ 10002 ]
Andy Fingerhut made changes -
Attachment clj-850-type-hinted-fn-abstractmethoderror-patch2.txt [ 10970 ]
Andy Fingerhut made changes -
Attachment clj-850-type-hinted-fn-abstractmethoderror-patch3.txt [ 11004 ]
Andy Fingerhut made changes -
Attachment clj-850-type-hinted-fn-abstractmethoderror-patch2.txt [ 10970 ]
Rich Hickey made changes -
Fix Version/s Release 1.5 [ 10150 ]
Rich Hickey made changes -
Approval Incomplete [ 10006 ]
Andy Fingerhut made changes -
Andy Fingerhut made changes -
Attachment clj-850-type-hinted-fn-abstractmethoderror-patch3.txt [ 11004 ]
Rich Hickey made changes -
Fix Version/s Release 1.5 [ 10150 ]
Ghadi Shayban made changes -
Attachment CLJ-850-conform-to-invokePrim.diff [ 11769 ]
Andy Fingerhut made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Rich Hickey made changes -
Fix Version/s Release 1.6 [ 10157 ]
Stuart Halloway made changes -
Assignee Stuart Halloway [ stu ]
Stuart Halloway made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Description See the following examples:

{noformat}
user=> (defn f1 ^String [^String s] s)
#'user/f1
user=> (f1 "foo")
"foo"
user=> (defn f2 ^long [^String s ^long i] i)
#'user/f2
user=> (f2 "foo" 1)
1
user=> (defn f3 ^String [^String s ^long i] s)
#'user/f3
user=> (f3 "foo" 1)
AbstractMethodError user$f3.invokePrim(Ljava/lang/Object;J)Ljava/lang/Object; user/eval8 (NO_SOURCE_FILE:6)
{noformat}
Summary: The CLJ-850-conform-to-invokePrim.diff patch is constructed per Rich's feedback, and appears good to me [Stu].

See the following examples:

{noformat}
user=> (defn f1 ^String [^String s] s)
#'user/f1
user=> (f1 "foo")
"foo"
user=> (defn f2 ^long [^String s ^long i] i)
#'user/f2
user=> (f2 "foo" 1)
1
user=> (defn f3 ^String [^String s ^long i] s)
#'user/f3
user=> (f3 "foo" 1)
AbstractMethodError user$f3.invokePrim(Ljava/lang/Object;J)Ljava/lang/Object; user/eval8 (NO_SOURCE_FILE:6)
{noformat}
Alex Miller made changes -
Description Summary: The CLJ-850-conform-to-invokePrim.diff patch is constructed per Rich's feedback, and appears good to me [Stu].

See the following examples:

{noformat}
user=> (defn f1 ^String [^String s] s)
#'user/f1
user=> (f1 "foo")
"foo"
user=> (defn f2 ^long [^String s ^long i] i)
#'user/f2
user=> (f2 "foo" 1)
1
user=> (defn f3 ^String [^String s ^long i] s)
#'user/f3
user=> (f3 "foo" 1)
AbstractMethodError user$f3.invokePrim(Ljava/lang/Object;J)Ljava/lang/Object; user/eval8 (NO_SOURCE_FILE:6)
{noformat}
Hinting the arg vector of a primitive-taking fn with a non-primitive type results in AbstractMethodError when invoked.

{noformat}
user=> (defn f1 ^String [^String s] s)
#'user/f1
user=> (f1 "foo")
"foo"
user=> (defn f2 ^long [^String s ^long i] i)
#'user/f2
user=> (f2 "foo" 1)
1
user=> (defn f3 ^String [^String s ^long i] s)
#'user/f3
user=> (f3 "foo" 1)
AbstractMethodError user$f3.invokePrim(Ljava/lang/Object;J)Ljava/lang/Object; user/eval8 (NO_SOURCE_FILE:6)
{noformat}

*Solution:* Add check to emit invokePrim with return type of double or long if appropriate, otherwise do prior behavior of emitting return type of Object.

*Patch:* The {{CLJ-850-conform-to-invokePrim.diff}} patch is constructed per Rich's feedback, and appears good to me [Stu].
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: