diff options
author | Philipp Stephani <phst@google.com> | 2022-09-13 17:11:53 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-09-13 17:11:53 +0200 |
commit | 6d8f5161ead689b7a2e44a7de0a695f0ab4c833b (patch) | |
tree | 006981ac2baf4bf7cc934fd3538a8629c1e8e8e3 /lisp/emacs-lisp | |
parent | 07ee1be052a45d8e6f671d0851f11c545dd9511a (diff) | |
download | emacs-6d8f5161ead689b7a2e44a7de0a695f0ab4c833b.tar.gz emacs-6d8f5161ead689b7a2e44a7de0a695f0ab4c833b.tar.bz2 emacs-6d8f5161ead689b7a2e44a7de0a695f0ab4c833b.zip |
Signal an error if a fallback cl-case is misplaced
* lisp/emacs-lisp/cl-macs.el (cl-case): Warn if the user passes a nil
key list (which would never match). Warn about quoted symbols that
should probably be unquoted.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-case-warning): New unit
test (bug#51368).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index f8fdc50251f..946d2c09a92 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -775,11 +775,16 @@ compared by `eql'. \(fn EXPR (KEYLIST BODY...)...)" (declare (indent 1) (debug (form &rest (sexp body)))) (macroexp-let2 macroexp-copyable-p temp expr - (let* ((head-list nil)) + (let* ((head-list nil) + (has-otherwise nil)) `(cond ,@(mapcar (lambda (c) - (cons (cond ((memq (car c) '(t otherwise)) t) + (cons (cond (has-otherwise + (error "Misplaced t or `otherwise' clause")) + ((memq (car c) '(t otherwise)) + (setq has-otherwise t) + t) ((eq (car c) 'cl--ecase-error-flag) `(error "cl-ecase failed: %s, %s" ,temp ',(reverse head-list))) |