macroexp.el: Fix missing warning for intermediate expansions

When a macro expanded to a call to an obsolete macro, we failed
to emit a warning for that use of the obsolete macro.

* lisp/emacs-lisp/macroexp.el (macroexp-macroexpand):
Use `macroexpand-1` to check obsolecence of intermediate expansions.

* test/lisp/emacs-lisp/macroexp-tests.el
(macroexp--test-obsolete-macro): New test.
This commit is contained in:
Stefan Monnier 2023-07-19 11:29:32 -04:00
parent b9a910a701
commit ca4bc9baf9
2 changed files with 29 additions and 15 deletions

View file

@ -227,21 +227,19 @@ It should normally be a symbol with position and it defaults to FORM."
(defun macroexp-macroexpand (form env)
"Like `macroexpand' but checking obsolescence."
(let* ((macroexpand-all-environment env)
(new-form
(macroexpand form env)))
(if (and (not (eq form new-form)) ;It was a macro call.
(car-safe form)
(symbolp (car form))
(get (car form) 'byte-obsolete-info))
(let* ((fun (car form))
(obsolete (get fun 'byte-obsolete-info)))
(macroexp-warn-and-return
(macroexp--obsolete-warning
fun obsolete
(if (symbolp (symbol-function fun))
"alias" "macro"))
new-form (list 'obsolete fun) nil fun))
new-form)))
new-form)
(while (not (eq form (setq new-form (macroexpand-1 form env))))
(let ((fun (car-safe form)))
(setq form
(if (and fun (symbolp fun)
(get fun 'byte-obsolete-info))
(macroexp-warn-and-return
(macroexp--obsolete-warning
fun (get fun 'byte-obsolete-info)
(if (symbolp (symbol-function fun)) "alias" "macro"))
new-form (list 'obsolete fun) nil fun)
new-form))))
form))
(defun macroexp--unfold-lambda (form &optional name)
(or name (setq name "anonymous lambda"))