defmethod resolves the multifn like a var (find clojure.core's)
(defmethod print-method ...) from the user ns auto-created a stray user/print-method with identity dispatch -> 'incorrect number of arguments 2' on (print-method x w). Resolve an unqualified multifn name through current-ns -> :refer -> clojure.core (like var resolution) before auto-creating. Fixes direct print-method/print-dup override calls; pairs with the cross-ns defmethod fix.
This commit is contained in:
parent
4d1ec44676
commit
b03da19ba8
1 changed files with 12 additions and 3 deletions
|
|
@ -56,11 +56,20 @@
|
|||
;; if absent (defmethod before defmulti — rare; identity dispatch as a fallback).
|
||||
(define (jolt-defmethod-setup mm-sym dval impl)
|
||||
(let* ((nm (symbol-t-name mm-sym))
|
||||
;; a QUALIFIED multifn (cf.mm/ext) resolves in its own ns (cross-ns
|
||||
;; defmethod), not the current one — else we'd auto-create a stray multifn.
|
||||
(sns (symbol-t-ns mm-sym))
|
||||
(qns (and sns (not (jolt-nil? sns)) (not (null? sns)) sns))
|
||||
(mns (if qns (or (chez-resolve-alias (chez-current-ns) qns) qns) (chez-current-ns)))
|
||||
;; resolve the multifn's HOME ns like a var: a qualified name in its own ns
|
||||
;; (cross-ns defmethod); an unqualified name via current ns -> :refer ->
|
||||
;; clojure.core, so (defmethod print-method ...) finds clojure.core's multifn
|
||||
;; instead of auto-creating a stray one in the current ns.
|
||||
(mns (cond
|
||||
(qns (or (chez-resolve-alias (chez-current-ns) qns) qns))
|
||||
((let ((c (var-cell-lookup (chez-current-ns) nm))) (and c (var-cell-defined? c)))
|
||||
(chez-current-ns))
|
||||
((chez-resolve-refer (chez-current-ns) nm))
|
||||
((let ((c (var-cell-lookup "clojure.core" nm))) (and c (var-cell-defined? c)))
|
||||
"clojure.core")
|
||||
(else (chez-current-ns))))
|
||||
(cur (var-deref mns nm))
|
||||
(mf (if (jolt-multifn? cur) cur
|
||||
(let ((m (make-jolt-multifn nm (var-deref "clojure.core" "identity")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue