macroexp-parse-body: correct parsing of empty body (bug#66136)

* lisp/emacs-lisp/macroexp.el (macroexp-parse-body):
Return an empty body even when there are declarations present.
Previously, the last declaration was considered part of the body,
which is only correct if the input consists of a single string.

Reported by Jens Schmidt.
This commit is contained in:
Mattias Engdegård 2023-09-25 14:40:11 +02:00
parent 6c99e4e384
commit f616edb4cc

View file

@ -525,12 +525,17 @@ definitions to shadow the loaded ones for use in file byte-compilation."
(defun macroexp-parse-body (body)
"Parse a function BODY into (DECLARATIONS . EXPS)."
(let ((decls ()))
(while (and (cdr body)
(let ((e (car body)))
(or (stringp e)
(memq (car-safe e)
'(:documentation declare interactive cl-declare)))))
(push (pop body) decls))
;; If there is only a string literal with nothing following, we
;; consider this to be part of the body (the return value) rather
;; than a declaration at this point.
(unless (and (null (cdr body)) (stringp (car body)))
(while
(and body
(let ((e (car body)))
(or (stringp e)
(memq (car-safe e)
'(:documentation declare interactive cl-declare)))))
(push (pop body) decls)))
(cons (nreverse decls) body)))
(defun macroexp-progn (exps)