clojure-emacs / cider-nrepl

A collection of nREPL middleware to enhance Clojure editors with common functionality like definition lookup, code completion, etc.
https://docs.cider.mx/cider-nrepl
672 stars 175 forks source link

Macroexpansion with lazy seqs occurs in the wrong ns #886

Closed yuhan0 closed 14 hours ago

yuhan0 commented 1 month ago

Expected behavior

Cider-nrepl's macroexpansion op should produce the same output as manually calling macroexpand.

Actual behavior

If the macro definition contains lazily evaluated seqs, their contents will be evaluated with the wrong dynamic ns bindings (in the user ns), which can result in incorrect / misleading expansions.

Steps to reproduce the problem

(ns repro)

(defmacro lazy []
  (cons (ns-name *ns*)
        (lazy-seq [(ns-name *ns*)])))

(macroexpand '(lazy))
;; => (repro repro)

(lazy) ;; <- M-x cider-macroexpand: (repro user)

Environment & Version information

cider-nrepl version

0.49.1

Java version

21.0.1

Operating system

MacOS 14

yuhan0 commented 1 month ago

Note: working on the fix, will submit a PR soon

alexander-yakushev commented 14 hours ago

Fixed in #894.