Have 'cl-case' warn about suspicious cases
* 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).
This commit is contained in:
parent
6d8f5161ea
commit
fffa53ff1a
2 changed files with 47 additions and 0 deletions
|
@ -788,6 +788,21 @@ compared by `eql'.
|
|||
((eq (car c) 'cl--ecase-error-flag)
|
||||
`(error "cl-ecase failed: %s, %s"
|
||||
,temp ',(reverse head-list)))
|
||||
((null (car c))
|
||||
(macroexp-warn-and-return
|
||||
"Case nil will never match"
|
||||
nil 'suspicious))
|
||||
((and (consp (car c)) (not (cddar c))
|
||||
(memq (caar c) '(quote function)))
|
||||
(macroexp-warn-and-return
|
||||
(format-message
|
||||
(concat "Case %s will match `%s'. If "
|
||||
"that's intended, write %s "
|
||||
"instead. Otherwise, don't "
|
||||
"quote `%s'.")
|
||||
(car c) (caar c) (list (cadar c) (caar c))
|
||||
(cadar c))
|
||||
`(cl-member ,temp ',(car c)) 'suspicious))
|
||||
((listp (car c))
|
||||
(setq head-list (append (car c) head-list))
|
||||
`(cl-member ,temp ',(car c)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue