Skip to content

Commit 5aaf6db

Browse files
frenchy64swannodette
authored andcommitted
CLJS-2807: Macroexpand failure with set literal
1 parent 88390da commit 5aaf6db

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,7 @@
35433543
(analyze-wrap-meta {:op :vector :env env :form form :items items :children [:items] :tag 'cljs.core/IVector})))
35443544

35453545
(defn analyze-set
3546-
[env form ]
3546+
[env form]
35473547
(let [expr-env (assoc env :context :expr)
35483548
items (disallowing-recur (mapv #(analyze expr-env %) form))]
35493549
(analyze-wrap-meta {:op :set :env env :form form :items items :children [:items] :tag 'cljs.core/ISet})))

src/main/clojure/cljs/compiler.cljc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,24 @@
235235
(declare emit-map emit-list emit-vector emit-set emit-js-object emit-js-array
236236
emit-with-meta emit-constants-comma-sep emit-constant)
237237

238+
(defn all-distinct? [xs]
239+
(apply distinct? xs))
240+
238241
#?(:clj
239242
(defn emit-constant-no-meta [x]
240243
(cond
241244
(seq? x) (emit-list x emit-constants-comma-sep)
242-
(map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep #(apply distinct? %))
245+
(map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?)
243246
(vector? x) (emit-vector x emit-constants-comma-sep)
244-
(set? x) (emit-set x emit-constants-comma-sep)
247+
(set? x) (emit-set x emit-constants-comma-sep all-distinct?)
245248
:else (emit-constant* x)))
246249
:cljs
247250
(defn emit-constant-no-meta [x]
248251
(cond
249252
(ana/cljs-seq? x) (emit-list x emit-constants-comma-sep)
250-
(ana/cljs-map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep #(apply distinct? %))
253+
(ana/cljs-map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?)
251254
(ana/cljs-vector? x) (emit-vector x emit-constants-comma-sep)
252-
(ana/cljs-set? x) (emit-set x emit-constants-comma-sep)
255+
(ana/cljs-set? x) (emit-set x emit-constants-comma-sep all-distinct?)
253256
:else (emit-constant* x))))
254257

255258
(defn emit-constant [v]
@@ -513,7 +516,7 @@
513516
(and (every? #(= (:op %) :const) items)
514517
(= (count (into #{} items)) (count items)))))
515518

516-
(defn emit-set [items comma-sep]
519+
(defn emit-set [items comma-sep distinct-constants?]
517520
(cond
518521
(empty? items)
519522
(emits "cljs.core.PersistentHashSet.EMPTY")
@@ -527,15 +530,7 @@
527530
(defmethod emit* :set
528531
[{:keys [items env]}]
529532
(emit-wrap env
530-
(cond
531-
(empty? items)
532-
(emits "cljs.core.PersistentHashSet.EMPTY")
533-
534-
(distinct-constants? items)
535-
(emits "new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, " (count items) ", ["
536-
(comma-sep (interleave items (repeat "null"))) "], null), null)")
537-
538-
:else (emits "cljs.core.PersistentHashSet.createAsIfByAssoc([" (comma-sep items) "])"))))
533+
(emit-set items comma-sep distinct-constants?)))
539534

540535
(defn emit-js-object [items emit-js-object-val]
541536
(emits "({")

src/test/cljs/cljs/core_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,3 +1607,7 @@
16071607
(let [x (map->CLJS-2787 {1 2})
16081608
y (map->CLJS-2787 x)]
16091609
(is (= x y))))
1610+
1611+
(deftest test-cljs-2807
1612+
(testing "Quoted sets should work"
1613+
(is (macroexpand '(fn [x] #{(into [] x)})))))

0 commit comments

Comments
 (0)