]> git.eshelyaron.com Git - emacs.git/commitdiff
Warn about `condition-case' with quoted condition names
authorMattias Engdegård <mattiase@acm.org>
Thu, 29 Dec 2022 11:00:50 +0000 (12:00 +0100)
committerMattias Engdegård <mattiase@acm.org>
Thu, 29 Dec 2022 11:24:47 +0000 (12:24 +0100)
* lisp/emacs-lisp/bytecomp.el (byte-compile-condition-case):
Add warning.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-warn-quoted-condition): Add test case.

lisp/emacs-lisp/bytecomp.el
test/lisp/emacs-lisp/bytecomp-tests.el

index 7571b4d409a1e32b69b19cda4103d318d75e8fcf..1a488977390cbdf66f467c831051e0cd9b5c3313 100644 (file)
@@ -4835,6 +4835,11 @@ binding slots have been popped."
 
     (dolist (clause (reverse clauses))
       (let ((condition (nth 1 clause)))
+        (when (and (eq (car-safe condition) 'quote)
+                   (cdr condition) (null (cddr condition)))
+          (byte-compile-warn-x
+           condition "`condition-case' condition should not be quoted: %S"
+           condition))
         (unless (consp condition) (setq condition (list condition)))
         (dolist (c condition)
           (unless (and c (symbolp c))
index 0d62283c04af917c20c6199a2e26ae615a66ad9e..61f4998f6ba7b5ca84e5beae585e2b74a60fa3e3 100644 (file)
@@ -923,6 +923,11 @@ byte-compiled.  Run with dynamic binding."
     `(defvar foo t ,bytecomp-tests--docstring)))
 
 (ert-deftest bytecomp-warn-quoted-condition ()
+  (bytecomp--with-warning-test
+      "Warning: `condition-case' condition should not be quoted: 'arith-error"
+    '(condition-case nil
+         (abc)
+       ('arith-error "ugh")))
   (bytecomp--with-warning-test
       "Warning: `ignore-error' condition argument should not be quoted: 'error"
     '(ignore-error 'error (abc))))