Skip to content

Commit eb16440

Browse files
zajacswannodette
authored andcommitted
follow-up on CLJS-460 defmulti ignores optional :hierarchy argument
1 parent 9ec238f commit eb16440

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9965,17 +9965,17 @@ reduces them without incurring seq initialization"
99659965
false)))
99669966

99679967
(defn- dominates
9968-
[x y prefer-table]
9969-
(or (prefers* x y prefer-table) (isa? x y)))
9968+
[x y prefer-table hierarchy]
9969+
(or (prefers* x y prefer-table) (isa? hierarchy x y)))
99709970

99719971
(defn- find-and-cache-best-method
99729972
[name dispatch-val hierarchy method-table prefer-table method-cache cached-hierarchy]
99739973
(let [best-entry (reduce (fn [be [k _ :as e]]
99749974
(if (isa? @hierarchy dispatch-val k)
9975-
(let [be2 (if (or (nil? be) (dominates k (first be) prefer-table))
9975+
(let [be2 (if (or (nil? be) (dominates k (first be) prefer-table @hierarchy))
99769976
e
99779977
be)]
9978-
(when-not (dominates (first be2) k prefer-table)
9978+
(when-not (dominates (first be2) k prefer-table @hierarchy)
99799979
(throw (js/Error.
99809980
(str "Multiple methods in multimethod '" name
99819981
"' match dispatch value: " dispatch-val " -> " k

src/test/cljs/cljs/core_test.cljs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@
243243
(defmulti foo2' identity)
244244
(defmethod foo2' 0 [x] x)
245245

246+
(def three-levels-h (-> (make-hierarchy)
247+
(derive :parent :gparent)
248+
(derive :child :parent)))
249+
250+
(defmulti multi-with-h (fn [v] v) :hierarchy #'three-levels-h)
251+
(defmethod multi-with-h :gparent [_] :gparent)
252+
(defmethod multi-with-h :parent [_] :parent)
253+
246254
(deftest test-multimethods-2
247255
(let [r (rect 4 13)
248256
c (circle 12)]
@@ -272,6 +280,7 @@
272280
(is (not (my-map? not-m))))
273281
;; multimethod hashing
274282
(is (= foo2' (ffirst {foo2' 1})))
283+
(is (= :parent (multi-with-h :child)))
275284
)))
276285

277286
(deftest test-transducers

0 commit comments

Comments
 (0)