sci icon indicating copy to clipboard operation
sci copied to clipboard

simple-dispatch extended to protocol not effective

Open borkdude opened this issue 2 years ago • 1 comments

Repro:

(ns user
  (:require [clojure.pprint :as pprint]))

(defprotocol Schema)
(defrecord ASchema []
  Schema)

(defrecord Foo [x])

(defmethod clojure.pprint/simple-dispatch user.Schema [_] (println "PRETTY"))

(prefer-method clojure.pprint/simple-dispatch user.Schema clojure.lang.IRecord)
(prefer-method clojure.pprint/simple-dispatch user.Schema java.util.Map)
(prefer-method clojure.pprint/simple-dispatch user.Schema clojure.lang.IPersistentMap)

(clojure.pprint/pprint (ASchema.))

This should print "PRETTY".

cc @frenchy64

borkdude avatar May 20 '22 15:05 borkdude

I'm guessing the most general fix for this is in clojure.core/isa?. Also worth testing print-method.

./bb
Babashka v0.8.3-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (defprotocol P) (defrecord R [] P)
#'user/P
user=> user.R
user=> (isa? user.R user.P)
false
clj
Clojure 1.11.1
user=> (defprotocol P) (defrecord R [] P)

P
user.R
user=> (isa? user.R user.P)
true

frenchy64 avatar May 20 '22 16:05 frenchy64