From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: 51368@debbugs.gnu.org, Philipp Stephani <p.stephani2@gmail.com>,
Lars Ingebrigtsen <larsi@gnus.org>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#51368: 29.0.50; `cl-case' should error on incorrect use
Date: Sun, 3 Sep 2023 15:40:03 +0200 [thread overview]
Message-ID: <03810284-957B-4ABD-8013-E9746FAFC17E@gmail.com> (raw)
In-Reply-To: <wvr4h7d6g8r0.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 944 bytes --]
> (cl-case EXP
> ((a b) FOO)
> ((a c) BAR))
>
> won't warn about the duplicate `a`.
I was curious how common this could be so I locally added a warning to the back-end in bytecomp that generates switches (attached), and bootstrapped Emacs. Results:
----------------
In gnus-cloud-decode-data:
lisp/gnus/gnus-cloud.el:154:6: Warning: Duplicated value in ‘cond’: base64-gzip
In netrc-parse:
lisp/obsolete/netrc.el:106:22: Warning: Duplicated value in ‘cond’: "macdef"
In org-read-date-analyze:
lisp/org/org.el:14041:15: Warning: Duplicated value in ‘cond’: ""
In org-html-latex-fragment:
lisp/org/ox-html.el:3099:8: Warning: Duplicated value in ‘cond’: t
-----------------
None of these are from `cl-case`. (`pcase` doesn't typically warn either but just drops the duplicate silently.)
I probably won't keep the warning because it's in the back-end and was very much a hack.
[-- Attachment #2: bytecomp-cond-switch-dup-warn.diff --]
[-- Type: application/octet-stream, Size: 2094 bytes --]
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 7feaf118b86..6bb95e7865b 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4621,7 +4621,10 @@ byte-compile--cond-switch-prefix
(setq switch-var var)
(setq switch-test
(byte-compile--common-test switch-test fn))
- (unless (member value keys)
+ (if (member value keys)
+ (byte-compile-warn-x
+ (car clauses)
+ "Duplicated value in `cond': %S" value)
(push value keys)
(push (cons (list value) (or body '(t))) cases))
t))))
@@ -4632,7 +4635,10 @@ byte-compile--cond-switch-prefix
(setq switch-var var)
(setq switch-test
(byte-compile--common-test switch-test 'eq))
- (unless (memq nil keys)
+ (if (memq nil keys)
+ (byte-compile-warn-x
+ (car clauses)
+ "Duplicated value in `cond': nil")
(push nil keys)
(push (cons (list nil) (or body '(t))) cases))
t)))
@@ -4655,7 +4661,10 @@ byte-compile--cond-switch-prefix
(member . equal))))))
(let ((vals nil))
(dolist (elem value)
- (unless (funcall fn elem keys)
+ (if (funcall fn elem keys)
+ (byte-compile-warn-x
+ (car clauses)
+ "Duplicated value in `cond': %S" elem)
(push elem vals)))
(when vals
(setq keys (append vals keys))
next prev parent reply other threads:[~2023-09-03 13:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 7:52 bug#51368: 29.0.50; `cl-case' should error on incorrect use Philipp Stephani
2021-10-24 8:16 ` Andreas Schwab
2021-10-24 12:46 ` Stefan Kangas
2021-10-24 17:48 ` Lars Ingebrigtsen
2021-10-31 18:53 ` Philipp Stephani
2021-11-01 13:31 ` Lars Ingebrigtsen
2021-11-12 19:34 ` Philipp Stephani
2021-11-14 1:09 ` Lars Ingebrigtsen
2021-11-14 15:08 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-13 15:19 ` Lars Ingebrigtsen
2022-09-13 16:12 ` Lars Ingebrigtsen
2022-09-13 16:15 ` Lars Ingebrigtsen
2023-09-03 8:48 ` Stefan Kangas
2022-10-02 21:39 ` Göktuğ Kayaalp
2023-09-03 13:40 ` Mattias Engdegård [this message]
2023-10-01 17:03 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=03810284-957B-4ABD-8013-E9746FAFC17E@gmail.com \
--to=mattias.engdegard@gmail.com \
--cc=51368@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=monnier@iro.umontreal.ca \
--cc=p.stephani2@gmail.com \
--cc=stefankangas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).