Commits

Anonymous committed 483904f

nicer error when trying to rebind non-dynamic var

  • Participants
  • Parent commits fbc7bc0

Comments (0)

Files changed (1)

      (let loop ((bindings (clojure-vector-elements bindings)))
        (match bindings
          (() '())
-         ((var value rest ...)
+         ((name value rest ...)
           (cons
            (list
-            (cond ((clojure-symbol? var)
-                   `(~clojure-var-value
-                     ,(clojure-compile
-                       (list (make-clojure-symbol #f 'var)
-                             var))))
-                  ((symbol? var) var)
+            (cond ((clojure-symbol? name)
+                   (let ((var (clojure-var-ref name)))
+                     (when (and var (not (clojure-dynamic? var)))
+                       (error 'clojure-compile
+                              "can't rebind non-dynamic var"
+                              var))
+
+                     `(~clojure-var-value
+                       ,(clojure-compile
+                         (list (make-clojure-symbol #f 'var)
+                               name)))))
+                  ((symbol? name) name)
                   (else (error 'clojure-compile
                                "variable names must be symbols"
                                bindings)))