Clojure

Type hinting for array classes does not work in binding forms

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4, Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    replicated on OpenJDK 7u9 on Ubuntu 12.04, and Hotspot 1.6.0_37 on OSX Lion

Description

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

Activity

Luke VanderHart made changes -
Field Original Value New Value
Description 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
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
Hide
Ghadi Shayban added a comment -

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 [^{:foo (Class/forName "not real")} bar 42]
bar)

neither this...

(let [^{gyorgy ligeti} a 42]
a)

Gyorgy Ligeti never resolves.

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

(let [a ^objects (make-array Object 2)]
(aget a 0))

Show
Ghadi Shayban added a comment - 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 [^{:foo (Class/forName "not real")} bar 42] bar) neither this... (let [^{gyorgy ligeti} a 42] a) Gyorgy Ligeti never resolves. These two equivalent examples don't reflect: (let [^objects a (make-array Object 2)] (aget a 0)) (let [a ^objects (make-array Object 2)] (aget a 0))
Hide
Ghadi Shayban added a comment -

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

Show
Ghadi Shayban added a comment - On only the left-hand side of a local binding, metadata on a symbol is not analyzed or evaluated.
Alex Miller made changes -
Labels Compiler bug interop typehints

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: