Welcome! Please see the About page for a little more info on how this works.

0 votes
in Compiler by
I'm trying to write a macro which generate reify forms using some reflection.

clojure.reflect produces type symbols similar to 'java.util.Iterator<>

Unfortunately, the compiler doesn't accept the <> syntax in type hints:

(reify Iterable (^{:tag java.util.Iterator} iterator [this] nil)) ; works

(reify Iterable (^{:tag java.util.Iterator<>} iterator [this] nil)) ;; fails
CompilerException java.lang.RuntimeException: java.lang.ClassNotFoundException: java.util.Iterator<>, compiling:(NO_SOURCE_PATH:1325)

It seems like the compiler should understand the <> just enough to strip it, rather than reject it. This would make it much easier to write correct macros involving type hinting and reflection.

The workaround I have been using is:

(defn hint
  "clojure.reflect demarks generics with angle brackets, but
   the compiler does not support generics in type hints"
  [obj tag]
  (let [tag (-> tag .toString (.replace "<>" "") symbol)]
    (with-meta obj {:tag tag}));)

2 Answers

0 votes
by

Comment made by: bbloom

I'm sorry, I got this wrong earlier. The problem is real, but it's arrays, not generics.

My workaround is useless... :-/

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-938 (reported by bbloom)
...