]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve check for misleading 'cl-case' cases (Bug#57915).
authorPhilipp Stephani <phst@google.com>
Mon, 19 Sep 2022 11:34:51 +0000 (13:34 +0200)
committerPhilipp Stephani <phst@google.com>
Mon, 19 Sep 2022 11:34:51 +0000 (13:34 +0200)
* lisp/emacs-lisp/cl-macs.el (cl-case): Check that the case is of the
form (quote FOO), not just (quote).
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-case-no-warning): New unit test.

lisp/emacs-lisp/cl-macs.el
test/lisp/emacs-lisp/cl-macs-tests.el

index 5d330f32d669138386164e41ccdc06bdfd35d9c1..beafee1d631fec98465d64741a18f643d33a9205 100644 (file)
@@ -792,7 +792,7 @@ compared by `eql'.
                           (macroexp-warn-and-return
                            "Case nil will never match"
                            nil 'suspicious))
-                         ((and (consp (car c)) (not (cddar c))
+                         ((and (consp (car c)) (cdar c) (not (cddar c))
                                (memq (caar c) '(quote function)))
                           (macroexp-warn-and-return
                            (format-message
index 83928775f188abdafcceb6c68fc810568cb01ef6..f742637ee35c8421fed17e2d2075e4e39007c818 100644 (file)
@@ -792,4 +792,15 @@ constructs."
                                               (should (equal messages
                                                              (concat "Warning: " message "\n"))))))))))
 
+(ert-deftest cl-case-no-warning ()
+  "Test that `cl-case' and `cl-ecase' don't warn in some valid cases.
+See Bug#57915."
+  (dolist (case '(quote (quote) function (function)))
+    (dolist (macro '(cl-case cl-ecase))
+      (let ((form `(,macro val (,case 1))))
+        (ert-info ((prin1-to-string form) :prefix "Form: ")
+          (ert-with-message-capture messages
+            (macroexpand form)
+            (should (string-empty-p messages))))))))
+
 ;;; cl-macs-tests.el ends here