Skip to content

Commit

Permalink
CLJS-1790: Port CLJ-1935: Use multimethod dispatch value method looku…
Browse files Browse the repository at this point in the history
…p to take hierarchies into account in multi-spec
  • Loading branch information
laurio authored and dnolen committed Sep 26, 2016
1 parent 71c9336 commit a4c627d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/cljs/cljs/spec.cljs
Expand Up @@ -442,8 +442,7 @@
([form mmvar retag gfn]
(let [id (random-uuid)
predx #(let [mm @mmvar]
(c/and (contains? (methods mm)
((-dispatch-fn mm) %))
(c/and (-get-method mm ((-dispatch-fn mm) %))
(mm %)))
dval #((-dispatch-fn @mmvar) %)
tag (if (keyword? retag)
Expand Down
10 changes: 10 additions & 0 deletions src/test/cljs/cljs/spec_test.cljs
Expand Up @@ -82,6 +82,16 @@
(is (= (s/form ::foo-1788)
'(cljs.spec/multi-spec cljs.spec-test/mm :mm/type))))

(def h-cljs-1790 (derive (make-hierarchy) :a :b))
(defmulti spec-type-1790 identity :hierarchy #'h-cljs-1790)
(defmethod spec-type-1790 :b [_]
(s/spec (constantly true)))

(deftest test-cljs-1790
(s/def ::multi (s/multi-spec spec-type-1790 identity))
(is (= :b (s/conform ::multi :b)))
(is (= :a (s/conform ::multi :a))))

;; Copied from Clojure spec tests

(def even-count? #(even? (count %)))
Expand Down

0 comments on commit a4c627d

Please sign in to comment.