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

0 votes
in Compiler by
Type hints don't work as expected in binding forms.

The following form results in a reflection warning:

    (let [^{:tag (Class/forName "[Ljava.lang.Object;")} a (make-array Object 2)]
      (aget a 0))

However, hinting does appear to work correctly on vars:

    (def ^{:tag (Class/forName "[Ljava.lang.Object;")} a (make-array Object 2))
    (aget a 0) ;; no reflection warning

3 Answers

0 votes
by

Comment made by: gshayban

It's a little more insidious than type hinting: the compiler doesn't evaluate metadata in the binding vec.

This doesn't throw the necessary exception...

(let (link: ^{:foo (Class/forName "not real")} bar 42)
bar)

neither this...

(let (link: ^{gyorgy ligeti} a 42)
a)

Gyorgy Ligeti never resolves.

These two equivalent examples don't reflect:
(let (link: ^objects a (make-array Object 2))
(aget a 0))

(let (link: a ^objects (make-array Object 2))
(aget a 0))

0 votes
by

Comment made by: gshayban

On only the left-hand side of a local binding, metadata on a symbol is not analyzed or evaluated.

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