1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Warn about condition-case without handlers

Omitting handlers from a `condition-case` form makes it useless
since no errors are caught.

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): New warning.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test case.
* etc/NEWS: Announce.
This commit is contained in:
Mattias Engdegård 2023-02-27 13:57:48 +01:00
parent 10d2b76eda
commit 443c249d85
3 changed files with 34 additions and 8 deletions

View file

@ -339,14 +339,19 @@ Assumes the caller has bound `macroexpand-all-environment'."
(`(cond . ,clauses)
(macroexp--cons fn (macroexp--all-clauses clauses) form))
(`(condition-case . ,(or `(,err ,body . ,handlers) pcase--dontcare))
(macroexp--cons
fn
(macroexp--cons err
(macroexp--cons (macroexp--expand-all body)
(macroexp--all-clauses handlers 1)
(cddr form))
(cdr form))
form))
(let ((exp-body (macroexp--expand-all body)))
(if handlers
(macroexp--cons fn
(macroexp--cons
err (macroexp--cons
exp-body
(macroexp--all-clauses handlers 1)
(cddr form))
(cdr form))
form)
(macroexp-warn-and-return
(format-message "`condition-case' without handlers")
exp-body (list 'suspicious 'condition-case) t form))))
(`(,(or 'defvar 'defconst) ,(and name (pred symbolp)) . ,_)
(push name macroexp--dynvars)
(macroexp--all-forms form 2))