aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-11-06 13:29:23 +0100
committerEli Zaretskii2024-11-06 15:27:33 +0200
commite88309eef30abca327c845fe4133d758d33cfb6b (patch)
treee6cd7619246c7b35e1b8af0ec9dd9f23e3e69cd7
parent3231af3727b450404efd6f49ddf5c95c5a8cbb0f (diff)
downloademacs-e88309eef30abca327c845fe4133d758d33cfb6b.tar.gz
emacs-e88309eef30abca327c845fe4133d758d33cfb6b.zip
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 9ee9154247454c18f9f75d0d32592b817d7e977a)
-rw-r--r--lisp/subr.el4
-rw-r--r--test/lisp/subr-tests.el6
2 files changed, 7 insertions, 3 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index b849d8d1b16..465795c7555 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -299,7 +299,7 @@ value of last one, or nil if there are none."
299 (if body 299 (if body
300 (list 'if cond (cons 'progn body)) 300 (list 'if cond (cons 'progn body))
301 (macroexp-warn-and-return (format-message "`when' with empty body") 301 (macroexp-warn-and-return (format-message "`when' with empty body")
302 cond '(empty-body when) t))) 302 (list 'progn cond nil) '(empty-body when) t)))
303 303
304(defmacro unless (cond &rest body) 304(defmacro unless (cond &rest body)
305 "If COND yields nil, do BODY, else return nil. 305 "If COND yields nil, do BODY, else return nil.
@@ -309,7 +309,7 @@ value of last one, or nil if there are none."
309 (if body 309 (if body
310 (cons 'if (cons cond (cons nil body))) 310 (cons 'if (cons cond (cons nil body)))
311 (macroexp-warn-and-return (format-message "`unless' with empty body") 311 (macroexp-warn-and-return (format-message "`unless' with empty body")
312 cond '(empty-body unless) t))) 312 (list 'progn cond nil) '(empty-body unless) t)))
313 313
314(defsubst subr-primitive-p (object) 314(defsubst subr-primitive-p (object)
315 "Return t if OBJECT is a built-in primitive written in C. 315 "Return t if OBJECT is a built-in primitive written in C.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 6f28e057342..e12e3c62e0c 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -454,7 +454,11 @@
454 x))) 454 x)))
455 (should (= x 2))) 455 (should (= x 2)))
456 (should (equal (macroexpand-all '(when a b c d)) 456 (should (equal (macroexpand-all '(when a b c d))
457 '(if a (progn b c d))))) 457 '(if a (progn b c d))))
458 (with-suppressed-warnings ((empty-body when unless))
459 (should (equal (when t) nil))
460 (should (equal (unless t) nil))
461 (should (equal (unless nil) nil))))
458 462
459(ert-deftest subr-test-xor () 463(ert-deftest subr-test-xor ()
460 "Test `xor'." 464 "Test `xor'."