ClojureScript

Unqualified use of excluded/re-assigned set! symbol causes compilation error

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Linux, using lein-cljsbuild with clojurescript 0.0-1513

Description

Compilation (with :optimizations :whitespace) fails when using an unqualified, re-assigned set! symbol, producing the following exception:

java.lang.AssertionError: Assert failed: set! target must be a field or a symbol naming a var targetexpr
analyzer.clj:578 cljs.analyzer/eval337[fn]
...

(This only occurs when using set! without qualification.)

Activity

Hide
David Nolen added a comment -

Can we get a code example please? Thanks.

Show
David Nolen added a comment - Can we get a code example please? Thanks.
Hide
Murphy McMahon added a comment - - edited

Sure, given something like this:

(ns store.local
  (:refer-clojure :exclude [set!]))

(defn set! [k x]
  (.setItem js/localStorage k x))

...The following code breaks during compilation for me (tested just now with r1552):

(ns app.core
  (:require [store.local :refer [set!]])
  (:refer-clojure :exclude [set!])

(defn store-items! [xs]
  (set! "data" xs))

...Whereas this code does not:

(ns app.core
  (:require [store.local :as store]))

(defn store-items! [xs]
  (store/set! "data" xs))
Show
Murphy McMahon added a comment - - edited Sure, given something like this:
(ns store.local
  (:refer-clojure :exclude [set!]))

(defn set! [k x]
  (.setItem js/localStorage k x))
...The following code breaks during compilation for me (tested just now with r1552):
(ns app.core
  (:require [store.local :refer [set!]])
  (:refer-clojure :exclude [set!])

(defn store-items! [xs]
  (set! "data" xs))
...Whereas this code does not:
(ns app.core
  (:require [store.local :as store]))

(defn store-items! [xs]
  (store/set! "data" xs))
Hide
David Nolen added a comment -

I looked a bit into the Clojure behavior, set! is a special form, one of the few things that can't be overridden. This behavior is the same as Clojure's and thus is unlikely to change. Unless you have some other argument for supporting this behavior I am inclined to close this ticket.

Show
David Nolen added a comment - I looked a bit into the Clojure behavior, set! is a special form, one of the few things that can't be overridden. This behavior is the same as Clojure's and thus is unlikely to change. Unless you have some other argument for supporting this behavior I am inclined to close this ticket.
Hide
Murphy McMahon added a comment -

No other argument, David; just that the behavior was unexpected since I was unaware set! is a special form. (Would it be helpful if the compiler warned against re-assignment then?) Anyhow, thanks for looking into it.

Show
Murphy McMahon added a comment - No other argument, David; just that the behavior was unexpected since I was unaware set! is a special form. (Would it be helpful if the compiler warned against re-assignment then?) Anyhow, thanks for looking into it.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: