core: fix jolt-265 — syntax-quote fully-qualifies core syms to clojure.core/ (#18)

Re-attempt of the deferred gap, now unblocked. The earlier uberscript break
wasn't qualification itself but an aliased-ref resolution bug it exposed:
resolve-var looked up ns-aliases (e.g. g/foo) against the analyzer's REBOUND
ctx-current-ns (jolt.analyzer, since the analyzer runs interpreted in its own
ns) instead of the namespace being compiled. A user's aliased refs failed
mid-compile (g/hello -> nil in the bundled standalone).

- resolve-var resolves aliases against :compile-ns when set (same ns
  h-current-ns uses), falling back to ctx-current-ns — correct for both modes.
- sq-symbol qualifies a resolved clojure.core name to clojure.core/<name>
  (Clojure hygiene); special forms stay bare; unresolved syms -> current ns.

Tests updated to the qualified behavior (features-test, reader-forms-spec).

Co-authored-by: Yogthos <yogthos@gmail.com>
This commit is contained in:
Dmitri Sotnikov 2026-06-10 11:41:42 +08:00 committed by GitHub
parent ae6e771b18
commit afb7d17352
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 10 deletions

View file

@ -149,7 +149,8 @@
:name (string (string/slice nm 0 -2) "__" (string (gensym)) "__auto")}]
(put gsmap nm g) g))
(special-symbol? nm) form
(ns-find (ctx-find-ns ctx "clojure.core") nm) form
(ns-find (ctx-find-ns ctx "clojure.core") nm)
{:jolt/type :symbol :ns "clojure.core" :name nm}
{:jolt/type :symbol :ns (ctx-current-ns ctx) :name nm}))
form))
@ -266,9 +267,13 @@
[ctx bindings sym-s]
(let [name (sym-s :name) ns (sym-s :ns)]
(if (not (nil? ns))
# Resolve ns aliases (e.g. `p/thrown?` where `p` is a require :as alias)
# so that aliased macros are recognized as macros, matching resolve-sym.
(let [current-ns (ctx-find-ns ctx (ctx-current-ns ctx))
# Resolve ns aliases (e.g. `p/thrown?` where `p` is a require :as alias) so
# aliased refs/macros resolve. During compilation the analyzer (interpreted,
# in jolt.analyzer) rebinds ctx-current-ns to its own ns, so look up the alias
# against the COMPILE ns (:compile-ns, the user's ns) when set — otherwise an
# aliased ref like g/foo wouldn't resolve mid-compile. Same ns h-current-ns uses.
(let [cur-name (or (get (ctx :env) :compile-ns) (ctx-current-ns ctx))
current-ns (ctx-find-ns ctx cur-name)
aliased-ns (ns-import-lookup current-ns ns)
target-ns (ctx-find-ns ctx (or aliased-ns ns))]
(ns-find target-ns name))