diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index ba0b6e7df..d316c559f 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -8052,7 +8052,9 @@ reduces them without incurring seq initialization" (let [len (alength ks)] (loop [i 0 ^not-native out (transient (.-EMPTY PersistentHashMap))] (if (< i len) - (recur (inc i) (-assoc! out (aget ks i) (aget vs i))) + (if (<= (alength vs) i) + (throw (js/Error. (str "No value supplied for key: " (aget ks i)))) + (recur (inc i) (-assoc! out (aget ks i) (aget vs i)))) (persistent! out)))))) (set! (.-createWithCheck PersistentHashMap) @@ -8926,7 +8928,10 @@ reduces them without incurring seq initialization" [& keyvals] (loop [in (seq keyvals), out (transient (.-EMPTY PersistentHashMap))] (if in - (recur (nnext in) (assoc! out (first in) (second in))) + (let [in' (next in)] + (if (nil? in') + (throw (js/Error. (str "No value supplied for key: " (first in)))) + (recur (next in') (assoc! out (first in) (first in')) ))) (persistent! out)))) (defn array-map diff --git a/src/main/clojure/cljs/core.cljc b/src/main/clojure/cljs/core.cljc index a055f5adf..ab3bc3bf9 100644 --- a/src/main/clojure/cljs/core.cljc +++ b/src/main/clojure/cljs/core.cljc @@ -2623,9 +2623,12 @@ (core/defmacro hash-map ([] `(.-EMPTY cljs.core/PersistentHashMap)) ([& kvs] - (core/let [pairs (partition 2 kvs) + (core/let [pairs (map + (core/fn [pair] + (remove #{::missing} pair)) + (partition 2 2 (repeat ::missing) kvs)) ks (map first pairs) - vs (map second pairs)] + vs (map second (take-while #(= 2 (count %)) pairs))] (vary-meta `(.fromArrays cljs.core/PersistentHashMap (array ~@ks) (array ~@vs)) assoc :tag 'cljs.core/PersistentHashMap)))) diff --git a/src/test/cljs/cljs/collections_test.cljs b/src/test/cljs/cljs/collections_test.cljs index 64f0fcbc0..9f44633d1 100644 --- a/src/test/cljs/cljs/collections_test.cljs +++ b/src/test/cljs/cljs/collections_test.cljs @@ -1084,6 +1084,13 @@ (testing "persistent vector invoke matches clojure" (is (thrown-with-msg? js/Error #"Key must be integer" ([1 2] nil))))) +(deftest test-cljs-3324 + (testing "hash-map behavior with missing values matches clojure" + (is (thrown-with-msg? js/Error #"No value supplied for key: :a" + (hash-map :a))) + (is (thrown-with-msg? js/Error #"No value supplied for key: :a" + (apply hash-map [:a]))))) + (comment (run-tests)