emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#43100: closed (28.0.50; pcase not binding variables conditionally)


From: GNU bug Tracking System
Subject: bug#43100: closed (28.0.50; pcase not binding variables conditionally)
Date: Tue, 02 Mar 2021 13:39:02 +0000

Your message dated Tue, 2 Mar 2021 13:38:01 +0000
with message-id 
<CAOqdjBftgQkPayYBbHO-COuUhSXWy1bjHP9tYX4dGVUc4VMggA@mail.gmail.com>
and subject line Re: bug#43100: 28.0.50; pcase not binding variables 
conditionally
has caused the debbugs.gnu.org bug report #43100,
regarding 28.0.50; pcase not binding variables conditionally
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
43100: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=43100
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 28.0.50; pcase not binding variables conditionally Date: Sat, 29 Aug 2020 09:41:10 +0000
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.

Attachment: 0001-Allow-variable-bindings-to-differ-across-pcase-alter.patch
Description: Text Data


--- End Message ---
--- Begin Message --- Subject: Re: bug#43100: 28.0.50; pcase not binding variables conditionally Date: Tue, 2 Mar 2021 13:38:01 +0000
On Sat, Aug 29, 2020 at 9:42 AM Pip Cet <pipcet@gmail.com> wrote:
>
> I'm having trouble with pcase's behavior.
>
> (pcase "a"
>   ((or (pred symbolp) name)
>    (let ((foo 'bar)) name)))

Stefan fixed this in 165353674e5fe7109ba9cbf526de0333902b7851, so I'm
closing this bug.

Pip


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]