Cross-ns def/require/use/defmethod through the spine (jolt-c2l1)

The per-form eval passed a FIXED compile-ns to every subform of a top-level do,
so a runtime (ns ...)/(in-ns ...) didn't redirect later defs/refs — defs landed
in the wrong ns and qualified refs hit host-static ("Unknown class"). Thread
the current ns: each subform analyzes in (chez-current-ns), which ns/in-ns move.

That exposed two more gaps, now fixed:
- use refers ALL of a target's public vars (a refer-all table consulted by
  chez-resolve-refer) — was bound to plain require (explicit :refer only).
- defmethod on a QUALIFIED multifn (cf.mm/ext from another ns) resolves in the
  symbol's ns, not the current one (was auto-creating a stray multifn).

Corpus 2684->2688, 0 new divergences; floor raised. No re-mint (runtime shims).
This commit is contained in:
Yogthos 2026-06-21 16:56:46 -04:00
parent 76f8274603
commit c788e86f1a
6 changed files with 50 additions and 8 deletions

View file

@ -56,11 +56,16 @@
;; 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))
(cur (var-deref (chez-current-ns) nm))
;; 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)))
(cur (var-deref mns nm))
(mf (if (jolt-multifn? cur) cur
(let ((m (make-jolt-multifn nm (var-deref "clojure.core" "identity")
(new-mm-table) kw-default #f (new-mm-table))))
(def-var! (chez-current-ns) nm m) m))))
(def-var! mns nm m) m))))
(hashtable-set! (jolt-multifn-methods mf) dval impl)
mf))