1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

Fix wrong value of when and unless with empty body (bug#74215)

Reported by Brennan Vincent.

* lisp/subr.el (when, unless): Return nil when the body is empty.
* test/lisp/subr-tests.el (subr-test-when): Add test cases.
This commit is contained in:
Mattias Engdegård 2024-11-06 13:29:23 +01:00
parent 1e3d72d962
commit 9ee9154247
2 changed files with 7 additions and 3 deletions

View File

@ -299,7 +299,7 @@ value of last one, or nil if there are none."
(if body
(list 'if cond (cons 'progn body))
(macroexp-warn-and-return (format-message "`when' with empty body")
cond '(empty-body when) t)))
(list 'progn cond nil) '(empty-body when) t)))
(defmacro unless (cond &rest body)
"If COND yields nil, do BODY, else return nil.
@ -309,7 +309,7 @@ value of last one, or nil if there are none."
(if body
(cons 'if (cons cond (cons nil body)))
(macroexp-warn-and-return (format-message "`unless' with empty body")
cond '(empty-body unless) t)))
(list 'progn cond nil) '(empty-body unless) t)))
(defsubst subr-primitive-p (object)
"Return t if OBJECT is a built-in primitive written in C.

View File

@ -454,7 +454,11 @@
x)))
(should (= x 2)))
(should (equal (macroexpand-all '(when a b c d))
'(if a (progn b c d)))))
'(if a (progn b c d))))
(with-suppressed-warnings ((empty-body when unless))
(should (equal (when t) nil))
(should (equal (unless t) nil))
(should (equal (unless nil) nil))))
(ert-deftest subr-test-xor ()
"Test `xor'."