Fix wrong value of when and unless with empty body (bug#74215)
* lisp/subr.el (when, unless): Return nil when the body is empty.
Reported by Brennan Vincent.
* test/lisp/subr-tests.el (subr-test-when): Add test cases.
(cherry picked from commit 9ee9154247)
This commit is contained in:
committed by
Eli Zaretskii
parent
3231af3727
commit
e88309eef3
@@ -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.
|
||||
|
||||
@@ -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'."
|
||||
|
||||
Reference in New Issue
Block a user