Subject: bug#26068: [PATCH] bug in generator function with pcase

From: Paul Pogonyshev <[email-masked]>
Date: Sat, 1 Apr 2017 15:44:16 +0200

Attached is the testcase from the bug as a patch. It might be best to
reformulate it without `pcase' though, to avoid depending on its
implementation details.

The testcase fails before the patch, passes now. So, I don't know
anything about `cl-flet', but the patch was not without reasons.

Paul

On 1 April 2017 at 15:08, Tino Calancha <[email-masked]> wrote:
> Paul Pogonyshev <[email-masked]> writes:
>
>> To reproduce:
>>
>> (iter-next (funcall (iter-lambda () (pcase (list 1 2)
>>                                       (`(,a ,b) (iter-yield (+ a b)))))))
>>
>> Patch is attached. I have no idea if it affects something else, but
>> matching symbols with `eq' on their names (`eq' on strings?!) seems
>> outright wrong to me.
> It looks also weird to me.  It seems written on purpose in order to
> not expand fuction names in `cl-symbol-macrolet'.
>
> Stefan has added a new test 2 days ago which fails after your
> patch:
> * test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-symbol-macrolet)
diff --git a/test/lisp/emacs-lisp/generator-tests.el b/test/lisp/emacs-lisp/generator-tests.el
index 1a567ac70f..11542ab15d 100644
--- a/test/lisp/emacs-lisp/generator-tests.el
+++ b/test/lisp/emacs-lisp/generator-tests.el
@@ -282,3 +282,10 @@ identical output.
 (ert-deftest cps-test-declarations-preserved ()
   (should (equal (documentation 'generator-with-docstring) "Documentation!"))
   (should (equal (get 'generator-with-docstring 'lisp-indent-function) 5)))
+
+;; Bug #26068.  The problem is that `pcase' uses several `x' symbols,
+;; which are not identical, but have the same name.
+(ert-deftest cps-test-symbols-with-same-name ()
+  (should (equal (iter-next (funcall (iter-lambda () (pcase (list 1 2)
+                                                       (`(,a ,b) (iter-yield (+ a b)))))))
+                 3)))