]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix pcase rx form snag with '?' and '??' (bug#44532)
authorMattias Engdegård <mattiase@acm.org>
Mon, 9 Nov 2020 16:11:05 +0000 (17:11 +0100)
committerMattias Engdegård <mattiase@acm.org>
Mon, 9 Nov 2020 16:28:37 +0000 (17:28 +0100)
This is a regression from Emacs 26.
Reported by Phillip Stephani.

* lisp/emacs-lisp/rx.el (rx--pcase-transform): Process ? and ?? correctly.
* test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add test case.

lisp/emacs-lisp/rx.el
test/lisp/emacs-lisp/rx-tests.el

index 8d8d071031c717da0b4ab79ffdeac6953108d313..76c3ac31b859e8d28c3b84a16fc73cddea647407 100644 (file)
@@ -1413,7 +1413,7 @@ into a plain rx-expression, collecting names into `rx--pcase-vars'."
                 (mapconcat #'symbol-name rx--pcase-vars " ")))
        `(backref ,index)))
     ((and `(,head . ,rest)
-          (guard (and (symbolp head)
+          (guard (and (or (symbolp head) (memq head '(?\s ??)))
                       (not (memq head '(literal regexp regex eval))))))
      (cons head (mapcar #'rx--pcase-transform rest)))
     (_ rx)))
index 59d8c600a20c3c5f4ede8387b9efc2fe36fb7b55..91b0884d4a941f34f33a27c6b45aa061e96b5b66 100644 (file)
   (let ((k "blue"))
     (should (equal (pcase "<blue>"
                      ((rx "<" (literal k) ">") 'ok))
-                   'ok))))
+                   'ok)))
+  (should (equal (pcase "abc"
+                   ((rx (? (let x alpha)) (?? (let y alnum)) ?c)
+                    (list x y)))
+                 '("a" "b"))))
 
 (ert-deftest rx-kleene ()
   "Test greedy and non-greedy repetition operators."