Skip to content

Commit 069dfb7

Browse files
committed
Fix another variant of print-method conflict
See code comment for rationale. Fixes #255.
1 parent 37faf9e commit 069dfb7

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/manifold/deferred.clj

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,24 +1522,39 @@
15221522
body))
15231523

15241524

1525-
1526-
(defmethod print-method IDeferred [o ^Writer w]
1525+
(defn- print-deferred [d ^Writer w]
15271526
(.write w
1528-
(str
1529-
"<< "
1530-
(if (realized? o)
1531-
(try
1532-
(let [x @o]
1533-
(pr-str x))
1534-
(catch Throwable e
1535-
(str "ERROR: " (pr-str e))))
1536-
"\u2026")
1537-
" >>")))
1538-
1539-
(prefer-method print-method IDeferred IDeref)
1540-
(prefer-method print-method IDeferred CompletionStage)
1541-
1542-
1527+
(str "<< "
1528+
(if (realized? d)
1529+
(try
1530+
(let [x @d]
1531+
(pr-str x))
1532+
(catch Throwable e
1533+
(str "ERROR: " (pr-str e))))
1534+
"\u2026")
1535+
" >>")))
1536+
1537+
(defmethod print-method IDeferred [o w]
1538+
(print-deferred o w))
1539+
1540+
;; Implement `print-method` for all concrete types, too, to be robust against third parties
1541+
;; providing conflicting implementations for any of the interfaces. The alternative of using
1542+
;; `prefer-method` would require us to also define preferences between *all* combinations of
1543+
;; interfaces (see https://clojure.atlassian.net/browse/CLJ-396). Not only is this very laborious,
1544+
;; it's also overstepping the scope of a library since we'd also have to do this for conflicts
1545+
;; between external interfaces (e.g. `IDeref` and `CompletionStage`).
1546+
1547+
(defmethod print-method Deferred [o w]
1548+
(print-deferred o w))
1549+
1550+
(defmethod print-method LeakAwareDeferred [o w]
1551+
(print-deferred o w))
1552+
1553+
(defmethod print-method SuccessDeferred [o w]
1554+
(print-deferred o w))
1555+
1556+
(defmethod print-method ErrorDeferred [o w]
1557+
(print-deferred o w))
15431558

15441559
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15451560
;; CompletionStage helper fns

0 commit comments

Comments
 (0)