Skip to content

Commit a4c627d

Browse files
lauriodnolen
authored andcommitted
CLJS-1790: Port CLJ-1935: Use multimethod dispatch value method lookup to take hierarchies into account in multi-spec
1 parent 71c9336 commit a4c627d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/cljs/cljs/spec.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@
442442
([form mmvar retag gfn]
443443
(let [id (random-uuid)
444444
predx #(let [mm @mmvar]
445-
(c/and (contains? (methods mm)
446-
((-dispatch-fn mm) %))
445+
(c/and (-get-method mm ((-dispatch-fn mm) %))
447446
(mm %)))
448447
dval #((-dispatch-fn @mmvar) %)
449448
tag (if (keyword? retag)

src/test/cljs/cljs/spec_test.cljs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@
8282
(is (= (s/form ::foo-1788)
8383
'(cljs.spec/multi-spec cljs.spec-test/mm :mm/type))))
8484

85+
(def h-cljs-1790 (derive (make-hierarchy) :a :b))
86+
(defmulti spec-type-1790 identity :hierarchy #'h-cljs-1790)
87+
(defmethod spec-type-1790 :b [_]
88+
(s/spec (constantly true)))
89+
90+
(deftest test-cljs-1790
91+
(s/def ::multi (s/multi-spec spec-type-1790 identity))
92+
(is (= :b (s/conform ::multi :b)))
93+
(is (= :a (s/conform ::multi :a))))
94+
8595
;; Copied from Clojure spec tests
8696

8797
(def even-count? #(even? (count %)))

0 commit comments

Comments
 (0)