From 4609333c7371f38660f6b4e216c250adcf42695b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 24 Sep 2024 14:01:26 -0400 Subject: [PATCH] Declare nested backquotes unsupported in Pcase patterns (bug#72328) The current behavior is inconsistent with that of the normal backquote macro, so to avoid surprises, warn about the use of nested backquotes. * lisp/emacs-lisp/pcase.el (pcase--expand-\`): Warn about nested backquotes. * lisp/emacs-lisp/testcover.el (testcover-analyze-coverage) (testcover-analyze-coverage-wrapped-form): Avoid nested backquotes (cherry picked from commit e8f5df5175170d36f526e46b63b3d428bb9a8950) --- etc/NEWS | 2 ++ lisp/emacs-lisp/pcase.el | 5 ++++- lisp/emacs-lisp/testcover.el | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 30b8c8fae98..aa0d1d6e734 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -365,6 +365,8 @@ mode. Now, one needs to say (midnight-mode +1) instead. * Incompatible Lisp Changes in Emacs 31.1 +** Nested backquotes are not supported any more in Pcase patterns. + ** The 'rx' category name 'chinese-two-byte' must now be spelled correctly. An old alternative name (without the first 'e') has been removed. diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index fd6b0c8db5c..fe62820f0cb 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -1172,7 +1172,10 @@ The predicate is the logical-AND of: (upatd (pcase--expand-\` (cdr qpat)))) (if (and (eq (car-safe upata) 'quote) (eq (car-safe upatd) 'quote)) `'(,(cadr upata) . ,(cadr upatd)) - `(and (pred consp) + `(and ,@(when (eq (car qpat) '\`) + `((guard ,(macroexp-warn-and-return + "Nested ` are not supported" t nil nil qpat)))) + (pred consp) (app car-safe ,upata) (app cdr-safe ,upatd))))) ((or (stringp qpat) (numberp qpat) (symbolp qpat)) `',qpat) diff --git a/lisp/emacs-lisp/testcover.el b/lisp/emacs-lisp/testcover.el index fb4a2a82d07..d916ca0f76a 100644 --- a/lisp/emacs-lisp/testcover.el +++ b/lisp/emacs-lisp/testcover.el @@ -469,7 +469,7 @@ or return multiple values." ;; form to look odd. See bug#25316. 'testcover-1value) - (`(\` ,bq-form) + (`(,'\` ,bq-form) (testcover-analyze-coverage-backquote-form bq-form)) ((or 't 'nil (pred keywordp)) @@ -548,7 +548,7 @@ FORM is treated as if it will be evaluated." 'testcover-1value)) ((pred atom) 'testcover-1value) - (`(\` ,bq-form) + (`(,'\` ,bq-form) (testcover-analyze-coverage-backquote-form bq-form)) (`(defconst ,sym ,val . ,_) (push sym testcover-module-constants) -- 2.39.5