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

0 votes
in Compiler by

In order to hint primitives, such as longs, you can hint with the symbol 'long. In some places, you can also use the class object java.lang.Long/TYPE. However, in some places, that doesn't work. This is particularly problematic when working with hints in macros, where subtle changes to when metadata is evaluated can lead to changes in whether or not hints are respected.

`
user=> (set! unchecked-math :warn-on-boxed)
:warn-on-boxed

user=> (defmacro mac []

     (let [field (with-meta 'x {:tag 'long})]
       (-> field meta :tag class prn)
       `(deftype Foo# [~field]
          clojure.lang.IDeref
          (deref [this#]
            (inc ~(with-meta field nil))))))

'user/mac

user=> (mac)
clojure.lang.Symbol

<java.lang.Class@1c76c583 class user.Foo13651auto__>

user=> (defmacro mac []

     (let [field (with-meta 'x {:tag java.lang.Long/TYPE})]
       (-> field meta :tag class prn)
       `(deftype Foo# [~field]
          clojure.lang.IDeref
          (deref [this#]
            (inc ~(with-meta field nil))))))

'user/mac

user=> (mac)
java.lang.Class
Boxed math warning, /private/var/folders/43/mnwlkd2s7r1gbjwq6t__mgt40000gn/T/form-init5463347341158437534.clj:1:1 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_inc(java.lang.Object).

<java.lang.Class@74626b21 class user.Foo13663auto__>

`

1 Answer

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