Skip to content

Commit 526e8a1

Browse files
authored
Merge pull request #237 from clj-commons/bugfix/print-method-promesa-conflict
Fix print-method bug
2 parents c3fc690 + 27a0423 commit 526e8a1

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/manifold/deferred.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@
15211521
" >>")))
15221522

15231523
(prefer-method print-method IDeferred IDeref)
1524+
(prefer-method print-method IDeferred CompletionStage)
15241525

15251526

15261527

test/manifold/deferred_test.clj

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
(ns manifold.deferred-test
2-
(:refer-clojure
3-
:exclude (realized? future loop))
2+
(:refer-clojure :exclude (realized? future loop))
43
(:require
5-
[manifold.utils :as utils]
64
[clojure.test :refer :all]
75
[manifold.test-utils :refer :all]
86
[manifold.deferred :as d]
97
[manifold.executor :as ex])
10-
(:import (java.util.concurrent CompletableFuture)))
8+
(:import
9+
(java.util.concurrent
10+
CompletableFuture
11+
CompletionStage)
12+
(manifold.deferred IDeferred)))
1113

1214
(defmacro future' [& body]
1315
`(d/future
@@ -403,3 +405,29 @@
403405
(d/success! d 1)
404406
(is (= 1 @@result)))))
405407

408+
;; Promesa adds CompletionStage to the print-method hierarchy, which can cause
409+
;; problems if neither is preferred over the other
410+
(deftest promesa-print-method-test
411+
(testing "print-method hierarchy compatibility with promesa")
412+
(try
413+
(let [print-method-dispatch-vals (-> print-method methods keys set)]
414+
(is (= IDeferred
415+
(get print-method-dispatch-vals IDeferred ::missing)))
416+
(is (= ::missing
417+
(get print-method-dispatch-vals CompletionStage ::missing)))
418+
419+
(let [d (d/deferred)]
420+
(is (instance? IDeferred d))
421+
(is (instance? CompletionStage d))
422+
423+
(testing "no conflicts - CompletionStage not dispatchable"
424+
(pr-str d))
425+
426+
(testing "no conflicts - preferred hierarchy established"
427+
(defmethod print-method CompletionStage [o ^java.io.Writer w]
428+
:noop)
429+
430+
(pr-str d))))
431+
432+
(finally
433+
(remove-method print-method CompletionStage))))

0 commit comments

Comments
 (0)