From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly Date: Wed, 21 Feb 2024 09:17:30 -0500 Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23004"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Jim Porter , 68509@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 21 16:28:15 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rcoW6-0005ec-7f for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Feb 2024 16:28:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcoOP-0001jj-Fc; Wed, 21 Feb 2024 10:20:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcoKe-0000wD-QL for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 10:16:25 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcnQm-0000Db-Tf for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 09:18:40 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rcnR7-0001J7-Ry for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 09:19:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Feb 2024 14:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68509 X-GNU-PR-Package: emacs Original-Received: via spool by 68509-submit@debbugs.gnu.org id=B68509.17085250874945 (code B ref 68509); Wed, 21 Feb 2024 14:19:01 +0000 Original-Received: (at 68509) by debbugs.gnu.org; 21 Feb 2024 14:18:07 +0000 Original-Received: from localhost ([127.0.0.1]:48046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcnQF-0001Hh-8L for submit@debbugs.gnu.org; Wed, 21 Feb 2024 09:18:07 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:44557) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcnQA-0001H8-PV for 68509@debbugs.gnu.org; Wed, 21 Feb 2024 09:18:05 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E1D38440BB6; Wed, 21 Feb 2024 09:17:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708525052; bh=dfCFibtlifrE/YYKmOYQPxJjPRV2sFBrvJ3JBooy7Ao=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=R3FLjiZ6wotfxRJ45KRez7z9a9TxceO7yZKPw3ddqLVJoAxsoSLEfzFwQZqIsMAj/ erMBx3mC/UI1KLNX7KocNvFarS5UHRxsvPZhFkPb163/WI34mLsK2y+e20sUk799Fo MhK06CqhJ6XY15DX6QQcxTiThoEJrPrIcrjZ5HTGjEe1Tc84bEk+L6upPXDsu9hvdE AyOF6/k+0SouxJFgSPzp5S4/TM8rkc8XhJwpiTpPZgTmoDjjBrF9olTg9Ui9BOFC4H /Aq4IGW3bBboo8YE3fjrkYxzaZFW7HLsqwbL2VYVHGP5GavHCCXMTlt07p+WngfCgJ mdPSHAj/nlkMw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5BA7A44024D; Wed, 21 Feb 2024 09:17:32 -0500 (EST) Original-Received: from milanesa (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2A288120679; Wed, 21 Feb 2024 09:17:32 -0500 (EST) In-Reply-To: <87y1berrh6.fsf@localhost> (Ihor Radchenko's message of "Wed, 21 Feb 2024 11:23:17 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280382 Archived-At: >>>> In the current use of those primitives, it's routine/normal/common for >>>> a pattern like `(,a ,b) to encounter lists of different length than 2, >>>> so a warning should be emitted only if specifically requested via an >>>> option/keyword. >>> But isn't it undocumented? >> >> AFAIK the "best" documentation we have for that is the one in >> `pcase-let`, which is indeed unsatisfactory. > > May you then describe in more details what is the intended behavior when > PATTERN does not match VALUE in destructuring? How 'bout the patch below? Stefan diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 78ad5b68a51..cf60cabe52b 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -1317,11 +1317,18 @@ Destructuring with pcase Patterns does the same as the previous example, except that it directly tries to extract @code{x} and @code{y} from @code{my-list} without first verifying if @code{my-list} is a list which has the right number of -elements and has @code{add} as its first element. The precise -behavior when the object does not actually match the pattern is -undefined, although the body will not be silently skipped: either an -error is signaled or the body is run with some of the variables -potentially bound to arbitrary values like @code{nil}. +elements and has @code{add} as its first element. + +The precise behavior when the object does not actually match the pattern +depends on the types, although the body will not be silently skipped: +either an error is signaled or the body is run with some of the +variables bound to arbitrary values like @code{nil}. +For example, the above pattern will result in @var{x} and @var{y} +being extracted with operations like @code{car} or @code{nth}, so they +will get value @code{nil} when @var{my-list} is too short. In contrast, +with a pattern like @code{`[add ,x ,y]}, those same variables would +be extracted using @code{aref} which would signal an error if +@var{my-list} is not an array or is too short. The pcase patterns that are useful for destructuring bindings are generally those described in @ref{Backquote Patterns}, since they