Skip to content

Commit 0d5b1ba

Browse files
authored
CLJS-3367: Backward conflict test in prefer-method causes incorrect exception (#170)
Reverse prefers* test arguments, add test case.
1 parent e07ace7 commit 0d5b1ba

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11490,7 +11490,7 @@ reduces them without incurring seq initialization"
1149011490
prefer-table method-cache cached-hierarchy default-dispatch-val)))
1149111491

1149211492
(-prefer-method [mf dispatch-val-x dispatch-val-y]
11493-
(when (prefers* dispatch-val-x dispatch-val-y prefer-table)
11493+
(when (prefers* dispatch-val-y dispatch-val-x prefer-table)
1149411494
(throw (js/Error. (str "Preference conflict in multimethod '" name "': " dispatch-val-y
1149511495
" is already preferred to " dispatch-val-x))))
1149611496
(swap! prefer-table

src/test/cljs/cljs/core_test.cljs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,16 @@
312312
(is (= :parent (multi-with-h :child)))
313313
)))
314314

315+
(def tmph (make-hierarchy))
316+
(defmulti fooz (fn [a b] (keyword b)) :hierarchy #'tmph)
317+
(defmethod fooz :a [a b] a)
318+
(defmethod fooz :b [a b] b)
319+
(prefer-method fooz :a :b)
320+
321+
(deftest test-cljs-3367-backward-conflict-prefers
322+
(testing "CLJS-3367: Verify no backward conflict in prefer-method"
323+
(is (some? (prefer-method fooz :a :b)))))
324+
315325
(deftest test-transducers
316326
(testing "Testing transducers"
317327
(is (= (sequence (map inc) (array 1 2 3)) '(2 3 4)))

0 commit comments

Comments
 (0)