defmethod on a referred multifn resolves to its home ns
A (defmethod m …) where m is :refer'd from another ns passed the bare symbol to defmethod-setup, which resolved it in the current ns and created a shadow multifn — the method never reached the real one. Resolve an unqualified name through the refer table (then current ns) so it lands on the referred multifn. The AOT build strips the ns form, so the refer table is empty in a binary; emit chez-register-refer!/-refer-all! per app ns alongside the existing alias registrations. build-app's fixture gains a defmethod on a referred multifn.
This commit is contained in:
parent
2c5b7fc27a
commit
44b7f39562
4 changed files with 37 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
|||
(ns app.core
|
||||
(:require [app.util :as util]
|
||||
(:require [app.util :as util :refer [greet]]
|
||||
[clojure.java.io :as io]))
|
||||
|
||||
;; An aliased cross-ns defmethod: 'util/greet is passed quoted to defmethod-setup,
|
||||
|
|
@ -7,6 +7,10 @@
|
|||
;; ns "util" and never reaches app.util/greet (the dispatch falls to :default).
|
||||
(defmethod util/greet :loud [_] "greet:loud")
|
||||
|
||||
;; A defmethod on a REFERRED multifn (bare `greet`): the AOT build must register
|
||||
;; the :refer so the bare name resolves to app.util/greet, not a shadow.
|
||||
(defmethod greet :soft [_] "greet:soft")
|
||||
|
||||
(defn -main [& args]
|
||||
;; the resource is baked into the binary (deps.edn :jolt/build :embed), so this
|
||||
;; resolves with no resources/ dir on disk, run from any cwd.
|
||||
|
|
@ -15,4 +19,5 @@
|
|||
(println "args:" (vec args))
|
||||
(println "sum:" (reduce + (map count args)))
|
||||
(println "greet-default:" (util/greet :unknown))
|
||||
(println "greet-loud:" (util/greet :loud)))
|
||||
(println "greet-loud:" (util/greet :loud))
|
||||
(println "greet-soft:" (util/greet :soft)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue