summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-07-14 13:41:16 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-07-27 16:50:45 -0400
commitec2037e5d93b6634d890d0a1266481aa224932d0 (patch)
tree4f6190bb5e021f4e475f8a299e852f653403f0d3
parent1f6834c3d8cf001c6bb4d52ab4221855989d7e8a (diff)
fix degenerate defrecords, #402
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--src/clj/clojure/core_deftype.clj6
-rw-r--r--test/clojure/test_clojure/protocols.clj5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj
index b0604c9e..3b531f05 100644
--- a/src/clj/clojure/core_deftype.clj
+++ b/src/clj/clojure/core_deftype.clj
@@ -195,8 +195,8 @@
`(entryAt [this# k#] (let [v# (.valAt this# k# this#)]
(when-not (identical? this# v#)
(clojure.lang.MapEntry. k# v#))))
- `(seq [this#] (concat [~@(map #(list `new `clojure.lang.MapEntry (keyword %) %) base-fields)]
- ~'__extmap))
+ `(seq [this#] (seq (concat [~@(map #(list `new `clojure.lang.MapEntry (keyword %) %) base-fields)]
+ ~'__extmap)))
`(assoc [this# k# ~gs]
(condp identical? k#
~@(mapcat (fn [fld]
@@ -212,7 +212,7 @@
(conj m
`(size [this#] (.count this#))
`(isEmpty [this#] (= 0 (.count this#)))
- `(containsValue [this# v#] (-> this# vals (.contains v#)))
+ `(containsValue [this# v#] (boolean (some #{v#} (vals this#))))
`(get [this# k#] (.valAt this# k#))
`(put [this# k# v#] (throw (UnsupportedOperationException.)))
`(remove [this# k#] (throw (UnsupportedOperationException.)))
diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj
index 257a73d8..d8d2ac7f 100644
--- a/test/clojure/test_clojure/protocols.clj
+++ b/test/clojure/test_clojure/protocols.clj
@@ -192,6 +192,11 @@
(is (= {:foo 1 :b 2} (set/rename-keys rec {:a :foo})))
(is (= {:a 11 :b 2 :c 10} (merge-with + rec {:a 10 :c 10})))))
+(deftest degenerate-defrecord-test
+ (let [empty (EmptyRecord.)]
+ (is (nil? (seq empty)))
+ (is (not (.containsValue empty :a)))))
+
(deftest defrecord-interfaces-test
(testing "java.util.Map"
(let [rec (r 1 2)]