Skip to content

Commit ebbd3ed

Browse files
mfikesswannodette
authored andcommitted
CLJS-3027: sorted-map can no longer be returned by a macro unless it has keyword keys
1 parent f2aaa2a commit ebbd3ed

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,12 +3495,16 @@
34953495
;; TODO: analyzed analyzed? should take pass name as qualified keyword arg
34963496
;; then compiler passes can mark/check individually - David
34973497

3498+
(defn- unsorted-map? [x]
3499+
(and (map? x)
3500+
(not (sorted? x))))
3501+
34983502
(defn analyzed
34993503
"Mark a form as being analyzed. Assumes x satisfies IMeta. Useful to suppress
35003504
warnings that will have been caught by a first compiler pass."
35013505
[x]
35023506
(cond
3503-
(map? x) (assoc x ::analyzed true)
3507+
(unsorted-map? x) (assoc x ::analyzed true)
35043508
:else (vary-meta x assoc ::analyzed true)))
35053509

35063510
(defn analyzed?
@@ -3509,7 +3513,7 @@
35093513
[x]
35103514
(boolean
35113515
(cond
3512-
(map? x) (::analyzed x)
3516+
(unsorted-map? x) (::analyzed x)
35133517
:else (::analyzed (meta x)))))
35143518

35153519
(defn- all-values?

src/test/cljs/cljs/macro_test.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
(ns cljs.macro-test
1010
(:refer-clojure :exclude [==])
1111
(:require [cljs.test :refer-macros [deftest is]])
12-
(:use-macros [cljs.macro-test.macros :only [==]])
12+
(:use-macros [cljs.macro-test.macros :only [== sm-cljs-3027]])
1313
(:require-macros [cljs.macro-test.cljs2852]))
1414

1515
(deftest test-macros
@@ -28,3 +28,6 @@
2828
(is (= '([x])) (cljs.macro-test.cljs2852/beta))
2929
(is (= '([x] [x y])) (cljs.macro-test.cljs2852/delta))
3030
(is (= '([x] [x & xs])) (cljs.macro-test.cljs2852/zeta)))
31+
32+
(deftest test-cljs-3027
33+
(is (= {"a" "b"} (sm-cljs-3027))))

src/test/cljs/cljs/macro_test/macros.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
(:refer-clojure :exclude [==]))
1111

1212
(defmacro == [a b]
13-
`(+ ~a ~b))
13+
`(+ ~a ~b))
14+
15+
(defmacro sm-cljs-3027 []
16+
(sorted-map "a" "b"))

0 commit comments

Comments
 (0)