babashka/sci

Referred var not resolved correctly when called from a macro

jeroenvandijk opened this issue · 1 comments

version

0.8.40

platform

JVM (openjdk version "11.0.20.1"), Os x

problem

When using a require with :refer all in namespace that was loaded via :load-fn, the referred var is not resolved correctly when wrapped in a macro.

repro

(let [ctx  {:load-fn (fn [_] {:file "other.clj"
                              :source " (ns other
                                          (:require [mylib.core :refer :all :as c]))
                                          (defn hello-fn [& body]
                                            (hello (apply str body)))

                                          (defmacro hello-macro [& body]
                                            `(hello (str ~@body)))

                                          (defmacro hello-macro-with-alias [& body]
                                            `(c/hello (str ~@body)))"})
            :namespaces {'mylib.core {'hello (fn [s] (str "hello " s))}}}]
  ;; This is ok
  (sci/eval-string (str '(do (require '[other :refer :all])
                             (hello-fn
                              "jeroen")))
                   ctx)

  ;; This is ok
  (sci/eval-string (str '(do (require '[other :refer :all])
                             (hello-macro-with-alias
                              "jeroen")))
                   ctx)


  ;; This is not ok, tries to resolve hello as `other/hello and not mylib.core/hello
  (sci/eval-string (str '(do (require '[other :refer :all])
                             (hello-macro
                              "jeroen")))
                   ctx)

)

expected behavior

The vars that are exposed via :refer :all should be resolved when called from a macro.

The issue here is that the values in the :namespaces map aren't properly vars. Changing that will make the above work.