Clojure

Using 'def with metadata {:type :anything} throws ClassCastException

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Ubuntu, lein 1.7.1 - lein repl
  • Approval:
    Vetted

Description

In lein 1.7.1 (and CCW) the form (def ^{:type :anything} mydef 1) throws "ClassCastException clojure.lang.Var cannot be cast to clojure.lang.IObj clojure.core/with-meta (core.clj:211)".
This seems to be due to setting the :type metadata. With other metadata keys it works well.

If it is intended to forbid setting the :type metadata, then there should be an appropriate error message instead of the ClassCastException

In lein2 repl which is using "REPL-y 0.1.0-beta8" the exception does not occur.

Full stacktrace:
java.lang.ClassCastException: clojure.lang.Var cannot be cast to clojure.lang.IObj
at clojure.core$with_meta.invoke (core.clj:211)
clojure.core$vary_meta.doInvoke (core.clj:617)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.core/fn (core_print.clj:76)
clojure.lang.MultiFn.invoke (MultiFn.java:167)
clojure.core$pr_on.invoke (core.clj:3266)
clojure.core$pr.invoke (core.clj:3278)
clojure.lang.AFn.applyToHelper (AFn.java:161)
clojure.lang.RestFn.applyTo (RestFn.java:132)
clojure.core$apply.invoke (core.clj:601)
clojure.core$prn.doInvoke (core.clj:3311)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.main$repl$read_eval_print__6405.invoke (main.clj:246)
clojure.main$repl$fn__6410.invoke (main.clj:266)
clojure.main$repl.doInvoke (main.clj:266)
clojure.lang.RestFn.invoke (RestFn.java:512)
user$eval27$acc_3261auto__30$fn_32.invoke (NO_SOURCE_FILE:1)
clojure.lang.AFn.run (AFn.java:24)
java.lang.Thread.run (Thread.java:662)

Activity

Hide
Stuart Halloway added a comment -

This is caused by the printer dispatch function

(defmulti print-method (fn [x writer]
                         (let [t (get (meta x) :type)]
                           (if (keyword? t) t (class x)))))

which ends up calling the default dispatch, which tries to vary-meta.

Show
Stuart Halloway added a comment - This is caused by the printer dispatch function
(defmulti print-method (fn [x writer]
                         (let [t (get (meta x) :type)]
                           (if (keyword? t) t (class x)))))
which ends up calling the default dispatch, which tries to vary-meta.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: