[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#51368: 29.0.50; `cl-case' should error on incorrect use
From: |
Philipp Stephani |
Subject: |
bug#51368: 29.0.50; `cl-case' should error on incorrect use |
Date: |
Sun, 31 Oct 2021 19:53:53 +0100 |
Am So., 24. Okt. 2021 um 19:48 Uhr schrieb Lars Ingebrigtsen <larsi@gnus.org>:
>
> Philipp Stephani <p.stephani2@gmail.com> writes:
>
> > This form demonstrates a few incorrect uses of `cl-case':
> >
> > (cl-case a
> > (nil 0) ; doesn't match anything
> > (t 1) ; matches everything, but too early
> > ('foo 2)) ; matches `quote' in addition to `foo'
> >
> > It would be nice if `cl-case' would signal an error or at least warn
> > about these at macroexpansion time, since they are somewhat subtle and
> > easy to get wrong.
>
> An error from the second case would be nice, and a warning on the first
> case, but the third case:
>
> (macroexpand
> '(cl-case a
> ('foo (message "foo"))))
> => (cond ((cl-member a ''foo) (message "foo")))
>
> and
>
> (equal ''foo (list 'quote 'foo))
>
> which, sure, whatever. But I guess the question is whether we can
> actually warn about that, because to the reader, the two forms are
> equivalent?
Yes, but the problem only arises if the user wants to match the symbol
`quote' plus exactly one other value. That should already be
exceedingly rare, and can be trivially rewritten by swapping the two
values (i.e. write (foo quote) instead of (quote foo)). So I think
issuing a warning or error for that case is worth it.
Assuming we'd want to prevent similar bugs with other reader
constructs, I think the only real problematic case is matching exactly
two of the symbols `function', `quote', `,', `,@', and `\`'. Maybe for
those cases we should just instruct people to write (cond (memq ...))
or similar.