GNU bug report logs -
#43100
28.0.50; pcase not binding variables conditionally
Previous Next
Reported by: Pip Cet <pipcet <at> gmail.com>
Date: Sat, 29 Aug 2020 09:42:02 UTC
Severity: normal
Found in version 28.0.50
Done: Pip Cet <pipcet <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I'm having trouble with pcase's behavior.
(pcase "a"
((or (pred symbolp) name)
(let ((foo 'bar)) name)))
throws an error. It shouldn't. (Note that the dummy "let" is necessary
to force the pcase code generation to use a function call).
I believe the culprit is the code around this comment in pcase.el
;; If some of `vars' were not found in `prevvars', that's
;; OK it just means those vars aren't present in all
;; branches, so they can be used within the pattern
;; (e.g. by a `guard/let/pred') but not in the branch.
I believe that's incorrect: using the variable in a condition-case
should work, as should conditional shadowing of an existing binding,
as in this case:
(let ((name "default"))
(pcase "a"
((or (pred symbolp) name)
name)))
(which works), or this case:
(let ((name "default"))
(pcase "a"
((or (pred symbolp) name)
(let ((foo 'bar)) name))))
(which doesn't).
I believe the right fix is not to share code for the same branch if it
uses different variables, as in the attached patch. It's possible this
increases codegen complexity in some construed cases, but in practice
that shouldn't be a problem.
[0001-Allow-variable-bindings-to-differ-across-pcase-alter.patch (text/x-patch, attachment)]
This bug report was last modified 4 years and 82 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.