diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index ae991f0a6..993a5d5fe 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -13142,7 +13142,7 @@ reduces them without incurring seq initialization" (set! (. SetLite -EMPTY) (SetLite. nil (. HashMapLite -EMPTY) empty-unordered-hash)) (defn set-lite - ":lite-mode version of set, not intended ot be used directly." + ":lite-mode version of set, not intended to be used directly." [coll] (if (set? coll) (-with-meta coll nil) @@ -13151,5 +13151,23 @@ reduces them without incurring seq initialization" #{} (loop [in in out (. SetLite -EMPTY)] (if-not (nil? in) - (recur (next in) (-conj out (first in))) + (recur (next in) (conj out (first in))) + out)))))) + +(defn set-lite-check + ":lite-mode version of set with check, not intended to be used directly." + [coll] + (if (set? coll) + (-with-meta coll nil) + (let [in (seq coll)] + (if (nil? in) + #{} + (loop [in in out (. SetLite -EMPTY) i 0] + (if-not (nil? in) + (let [x (first in) + out' (conj out x) + i' (inc i)] + (if-not (== i' (count out')) + (throw (js/Error. (str_ "Duplicate key: " x))) + (recur (next in) out' i'))) out)))))) diff --git a/src/main/clojure/cljs/compiler.cljc b/src/main/clojure/cljs/compiler.cljc index 1fbf54ec2..4bc7ea215 100644 --- a/src/main/clojure/cljs/compiler.cljc +++ b/src/main/clojure/cljs/compiler.cljc @@ -614,12 +614,17 @@ (emits "new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, " (count items) ", [" (comma-sep (interleave items (repeat "null"))) "], null), null)") - :else (emits "cljs.core.PersistentHashSet.createAsIfByAssoc([" (comma-sep items) "])"))) + :else (emits "cljs.core.PersistentHashSet.createWithCheck([" (comma-sep items) "])"))) (defn emit-lite-set [items comma-sep distinct-constants?] - (if (empty? items) + (cond + (empty? items) (emits "cljs.core.SetLite.EMPTY") - (emits "cljs.core.set_lite([" (comma-sep items) "])"))) + + (distinct-constants? items) + (emits "cljs.core.set_lite([" (comma-sep items) "])") + + :else (emits "cljs.core.set_lite_check([" (comma-sep items) "])"))) (defmethod emit* :set [{:keys [items env]}] diff --git a/src/test/cljs/cljs/core_test.cljs b/src/test/cljs/cljs/core_test.cljs index 01f6f0b52..8bff60d3b 100644 --- a/src/test/cljs/cljs/core_test.cljs +++ b/src/test/cljs/cljs/core_test.cljs @@ -824,9 +824,6 @@ (def some-x 1) (def some-y 1) -(deftest test-583 - (is (= (count #{some-x some-y}) 1))) - (deftest test-584 (is (= (count {some-x :foo some-y :bar}) 1))) @@ -2012,3 +2009,7 @@ (deftest test-instance-method-new (is (= ["FOO" "BAR" "BAZ"] (map String/.toUpperCase ["foo" "bar" "baz"])))) + +(deftest test-cljs-3415 + (let [a 1 b 1] + (is (thrown? js/Error #{a b})))) \ No newline at end of file