Skip to content

Commit

Permalink
Fix regressions with symbol/keyword destructuring.
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <[email protected]>
  • Loading branch information
ragnard authored and stuarthalloway committed Sep 11, 2015
1 parent b007c2d commit df85e2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/clj/clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4294,24 +4294,24 @@
(if (seq bes)
(let [bb (key (first bes))
bk (val (first bes))
has-default (contains? defaults bb)]
(recur (pb ret bb (if has-default
(list `get gmap bk (defaults bb))
(list `get gmap bk)))
bv (if (contains? defaults bb)
(list `get gmap bk (defaults bb))
(list `get gmap bk))]
(recur (cond
(symbol? bb) (-> ret (conj (if (namespace bb) (symbol (name bb)) bb)) (conj bv))
(keyword? bb) (-> ret (conj (symbol (name bb)) bv))
:else (pb ret bb bv))
(next bes)))
ret))))]
(cond
(symbol? b) (-> bvec (conj (if (namespace b) (symbol (name b)) b)) (conj v))
(keyword? b) (-> bvec (conj (symbol (name b))) (conj v))
(vector? b) (pvec bvec b v)
(map? b) (pmap bvec b v)
:else (throw (new Exception (str "Unsupported binding form: " b))))))
(symbol? b) (-> bvec (conj b) (conj v))
(vector? b) (pvec bvec b v)
(map? b) (pmap bvec b v)
:else (throw (new Exception (str "Unsupported binding form: " b))))))
process-entry (fn [bvec b] (pb bvec (first b) (second b)))]
(if (every? symbol? (map first bents))
bindings
(if-let [kwbs (seq (filter #(keyword? (first %)) bents))]
(throw (new Exception (str "Unsupported binding key: " (ffirst kwbs))))
(reduce1 process-entry [] bents)))))
(reduce1 process-entry [] bents))))

(defmacro let
"binding => binding-form init-expr
Expand Down
16 changes: 13 additions & 3 deletions test/clojure/test_clojure/special.clj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@
(is (= 2 d))))

(deftest keywords-not-allowed-in-let-bindings
(is (thrown-with-msg? Exception #"Unsupported binding key: :a"
(is (thrown-with-msg? Exception #"Unsupported binding form: :a"
(eval '(let [:a 1] a))))
(is (thrown-with-msg? Exception #"Unsupported binding key: :a/b"
(eval '(let [:a/b 1] b)))))
(is (thrown-with-msg? Exception #"Unsupported binding form: :a/b"
(eval '(let [:a/b 1] b))))
(is (thrown-with-msg? Exception #"Unsupported binding form: :a"
(eval '(let [[:a] [1]] a))))
(is (thrown-with-msg? Exception #"Unsupported binding form: :a/b"
(eval '(let [[:a/b] [1]] b)))))

(deftest namespaced-syms-only-allowed-in-map-destructuring
(is (thrown-with-msg? Exception #"Can't let qualified name: a/x"
(eval '(let [a/x 1, [y] [1]] x))))
(is (thrown-with-msg? Exception #"Can't let qualified name: a/x"
(eval '(let [[a/x] [1]] x)))))

(require '[clojure.string :as s])
(deftest resolve-keyword-ns-alias-in-destructuring
Expand Down

0 comments on commit df85e2e

Please sign in to comment.