From 165353674e5fe7109ba9cbf526de0333902b7851 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 1 Mar 2021 23:57:34 -0500 Subject: * lisp/emacs-lisp/pcase.el: Bind all the vars in `or` patterns Improve the handling of `or` patterns where not all sub-patterns bind the same set of variables. This used to be "unsupported" and behaved in somewhat unpredictable ways. (pcase--expand): Rewrite. (pcase-codegen): Delete. * doc/lispref/control.texi (pcase Macro): Adjust accordingly. Also remove the warning about "at least two" sub patterns. These work fine, AFAICT, and if not we should fix it. * test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-or-vars): New test. --- test/lisp/emacs-lisp/pcase-tests.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/lisp/emacs-lisp/pcase-tests.el b/test/lisp/emacs-lisp/pcase-tests.el index 6ddeb7b622b..2120139ec18 100644 --- a/test/lisp/emacs-lisp/pcase-tests.el +++ b/test/lisp/emacs-lisp/pcase-tests.el @@ -85,13 +85,19 @@ (ert-deftest pcase-tests-bug46786 () (let ((self 'outer)) + (ignore self) (should (equal (cl-macrolet ((show-self () `(list 'self self))) - (pcase-let ((`(,self ,self2) '(inner "2"))) + (pcase-let ((`(,self ,_self2) '(inner "2"))) (show-self))) '(self inner))))) -;; Local Variables: -;; no-byte-compile: t -;; End: +(ert-deftest pcase-tests-or-vars () + (let ((f (lambda (v) + (pcase v + ((or (and 'b1 (let x1 4) (let x2 5)) + (and 'b2 (let y1 8) (let y2 9))) + (list x1 x2 y1 y2)))))) + (should (equal (funcall f 'b1) '(4 5 nil nil))) + (should (equal (funcall f 'b2) '(nil nil 8 9))))) ;;; pcase-tests.el ends here. -- cgit v1.2.1