<< Back to previous view

[CLJ-851] Type-hinting a var with primitive array pseudo-class results in IllegalArgumentException when the var is used as an arg Created: 10/Oct/11  Updated: 01/Mar/13  Resolved: 09/Nov/12

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Alexander Taggart Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None

Attachments: Text File CLJ-851-test.patch    

 Description   

Example:

user=> (def ^longs la (long-array 0))
#'user/la
user=> (defn foo [] (alength la))
CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$longs@32dfcb47, compiling:(NO_SOURCE_PATH:9) 

Workaround: use the class string, e.g., ^"[J"



 Comments   
Comment by Ben Smith-Mannschott [ 15/Oct/11 11:40 AM ]

CLJ-851-test.patch

Provides a test to reproduce this issue, as well as a test that shows that the workaround of using ^"[J" as type hint works correctly.

Comment by Ben Smith-Mannschott [ 16/Oct/11 2:23 AM ]

OK, I see the problem here: longs plays two roles in Clojure:

  1. As an unqualified symbol, it's taken to mean long[].class.
  2. clojure.core/longs is a definline function which calls clojure.lang.Numbers.longs(...).

The example in the issue description is expecting the first interpretation, but what we're actually getting is the second interpretation, i.e. the :tag is not a symbol longs, but rather a function (an instance of the class clojure.core$longs, to be precise).

So, it's as if we'd written this:

(def ^{:tag clojure.core/longs} la (long-array 0))

When really, we meant this:

(def ^{:tag 'longs} la (long-array 0))

While the behavior described by this issue is confusing, it looks to me like it's not a bug.

Comment by Stuart Sierra [ 09/Nov/12 8:39 AM ]

Correct, this is not a bug. The reader will attempt to resolve symbols in the ^tag metadata form, so that it can resolve unqualified class names.

Generated at Sun Nov 23 21:02:20 CST 2014 using JIRA 4.4#649-r158309.