aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2025-10-18 17:45:07 -0400
committerStefan Monnier2025-10-18 17:45:07 -0400
commit4ec24ce2a13661e3cd721b795f36bf76e0428abe (patch)
tree14898c76b976cff249762d8472512bd98b53c8f2 /test
parent48357dc612ffe2d6b286e3f99a0e7e9c80cfcbb8 (diff)
downloademacs-4ec24ce2a13661e3cd721b795f36bf76e0428abe.tar.gz
emacs-4ec24ce2a13661e3cd721b795f36bf76e0428abe.zip
(eval-and-compile): Preserve the surrounding lexical context
Implement a better fix for bug#79634. * lisp/emacs-lisp/byte-run.el (eval-and-compile): * lisp/emacs-lisp/bytecomp.el (byte-compile-initial-macro-environment) <eval-and-compile>: Preserve the surrounding lexical context (the part available during macroexpansion, i.e. which vars are dynbound). * lisp/emacs-lisp/rx.el (<pcase> rx): Remove workaround. * test/lisp/emacs-lisp/macroexp-tests.el (macroexp--dynbound-eval-and-compile): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/macroexp-tests.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/macroexp-tests.el b/test/lisp/emacs-lisp/macroexp-tests.el
index 817c5d7be49..91d66986bc6 100644
--- a/test/lisp/emacs-lisp/macroexp-tests.el
+++ b/test/lisp/emacs-lisp/macroexp-tests.el
@@ -124,6 +124,48 @@
124 (dyn dyn dyn dyn) 124 (dyn dyn dyn dyn)
125 (dyn dyn dyn lex)))))) 125 (dyn dyn dyn lex))))))
126 126
127(ert-deftest macroexp--dynbound-eval-and-compile ()
128 (let ((code1 '(progn
129 (eval-and-compile
130 (defun my-foo () (bound-and-true-p my-foo))
131 (defun my-identity (x)
132 (defvar my-foo)
133 (let ((my-foo x))
134 (my-foo))))
135 (defmacro my-toto (y)
136 `(list ',y ',(my-identity y)))
137 (eval-when-compile (my-toto 7))))
138 (code2 '(progn
139 (defvar my-foo)
140 (eval-and-compile
141 (defun my-foo () (bound-and-true-p my-foo))
142 (defun my-identity (x)
143 (let ((my-foo x))
144 (my-foo))))
145 (defmacro my-toto (y)
146 `(list ',y ',(my-identity y)))
147 (eval-when-compile (my-toto 7))))
148 (code3 '(progn
149 (eval-and-compile
150 (defvar my-foo)
151 (defun my-foo () (bound-and-true-p my-foo))
152 (defun my-identity (x)
153 (let ((my-foo x))
154 (my-foo))))
155 (defmacro my-toto (y)
156 `(list ',y ',(my-identity y)))
157 (eval-when-compile (my-toto 7)))))
158 (should (equal (eval code1 t) '(7 7)))
159 (should (equal (eval code2 t) '(7 7)))
160 (should (equal (eval code3 t) '(7 7)))
161 (should (equal (eval (let ((lexical-binding t)) (byte-compile code1)) t)
162 '(7 7)))
163 (should (equal (eval (let ((lexical-binding t)) (byte-compile code2)) t)
164 '(7 7)))
165 (should (equal (eval (let ((lexical-binding t)) (byte-compile code3)) t)
166 '(7 7)))
167 ))
168
127(defmacro macroexp--test-macro1 () 169(defmacro macroexp--test-macro1 ()
128 (declare (obsolete "new-replacement" nil)) 170 (declare (obsolete "new-replacement" nil))
129 1) 171 1)