GNU bug report logs - #33890
27.0.50; Incorrect behaviour of cl-loop macro

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Quek Yu Han <qythium@HIDDEN>; Keywords: confirmed; merged with #32506; dated Thu, 27 Dec 2018 17:37:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Merged 32506 33890. Request was from Glenn Morris <rgm@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 33890 <at> debbugs.gnu.org:


Received: (at 33890) by debbugs.gnu.org; 31 Dec 2018 06:22:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Dec 31 01:22:55 2018
Received: from localhost ([127.0.0.1]:42782 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gdqyV-0006iO-IW
	for submit <at> debbugs.gnu.org; Mon, 31 Dec 2018 01:22:55 -0500
Received: from eggsout.gnu.org ([209.51.188.92]:48585)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <rgm@HIDDEN>) id 1gdqyT-0006iF-C7
 for 33890 <at> debbugs.gnu.org; Mon, 31 Dec 2018 01:22:53 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <rgm@HIDDEN>) id 1gdqyS-0008OL-8C
 for 33890 <at> debbugs.gnu.org; Mon, 31 Dec 2018 01:22:52 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled
 version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58961)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <rgm@HIDDEN>)
 id 1gdqyM-0008Cn-AX; Mon, 31 Dec 2018 01:22:46 -0500
Received: from rgm by fencepost.gnu.org with local (Exim 4.82)
 (envelope-from <rgm@HIDDEN>)
 id 1gdqyC-0003nq-97; Mon, 31 Dec 2018 01:22:37 -0500
From: Glenn Morris <rgm@HIDDEN>
To: Quek Yu Han <qythium@HIDDEN>
Subject: Re: bug#33890: 27.0.50; Incorrect behaviour of cl-loop macro
References: <CAGCUw0jQX_rp7ZhmFr4FLUmH0BUzeR48MObuFR-CHX5LsuTMvA@HIDDEN>
X-Spook: SAPO beanpole terrorist Bridge UOP Drug trade clones
X-Ran: 0@/c^edKg5-ya)C2>xt_D>c!%~BA_qGxn-W[e#7DwJ,Z~Iz~ZKd}j<'-[S~(+0}%=;!TaI
X-Hue: brightwhite
X-Attribution: GM
Date: Mon, 31 Dec 2018 01:22:34 -0500
In-Reply-To: <CAGCUw0jQX_rp7ZhmFr4FLUmH0BUzeR48MObuFR-CHX5LsuTMvA@HIDDEN>
 (Quek Yu Han's message of "Thu, 27 Dec 2018 04:28:59 -0500")
Message-ID: <e0wonqcj11.fsf@HIDDEN>
User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2001:4830:134:3::e
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 33890
Cc: 33890 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Quek Yu Han wrote:

> It appears that a change to the `cl-loop` macro in Emacs 27 introduced a
> bug where certain clauses would be evaluated more than once in a loop
> with a "when" clause.

This seems to be another manifestation of https://debbugs.gnu.org/32506
due to a0365437c9ee308ad7978e436631020f513b25e7.







Information forwarded to bug-gnu-emacs@HIDDEN:
bug#33890; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 27 Dec 2018 17:36:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Dec 27 12:36:35 2018
Received: from localhost ([127.0.0.1]:39515 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gcZaF-0006Or-1D
	for submit <at> debbugs.gnu.org; Thu, 27 Dec 2018 12:36:35 -0500
Received: from eggs.gnu.org ([208.118.235.92]:57653)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <qythium@HIDDEN>) id 1gcRyY-0006Ha-MM
 for submit <at> debbugs.gnu.org; Thu, 27 Dec 2018 04:29:11 -0500
Received: from lists.gnu.org ([208.118.235.17]:40504)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <qythium@HIDDEN>) id 1gcRyT-0007RX-92
 for submit <at> debbugs.gnu.org; Thu, 27 Dec 2018 04:29:05 -0500
Received: from eggs.gnu.org ([208.118.235.92]:40126)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <qythium@HIDDEN>) id 1gcRyR-0003wv-K9
 for bug-gnu-emacs@HIDDEN; Thu, 27 Dec 2018 04:29:05 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM,
 UNPARSEABLE_RELAY autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <qythium@HIDDEN>) id 1gcRyQ-0007ED-4w
 for bug-gnu-emacs@HIDDEN; Thu, 27 Dec 2018 04:29:03 -0500
Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]:41791)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <qythium@HIDDEN>) id 1gcRyP-00079Y-Ry
 for bug-gnu-emacs@HIDDEN; Thu, 27 Dec 2018 04:29:02 -0500
Received: by mail-yb1-xb30.google.com with SMTP id j10so4079776ybj.8
 for <bug-gnu-emacs@HIDDEN>; Thu, 27 Dec 2018 01:29:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:mime-version:date:message-id:subject:to
 :content-transfer-encoding;
 bh=MwXJyW1smoQSmWW0cRiq68GDc69dgK7Aad6tCkM95Sc=;
 b=QNvjsAHZ4rxF571rc+VWvpZcBHzwDQnx0AO0JJRscrwfaB+pWdKrDxr4vZVCX9Q4Wd
 0tiafNEhqUjA8zwRcqHOpvyjLGAA6AAV/5qpSGGoFPXkc+uMj1OKKAsqbDf/YPSzUx6/
 qzmw0fNF9/YhmsB6Ekcfz0U70fPRbyjZWuautzO4ArXZK/QYv0cVy5Pfy+DzRF2r4cyI
 fROfUjDWYDVvADlKG7XjaVQw69o3EYq83377SOqwPJh+GD6Xa4vemXhJWJTcKKiVY2gg
 I71hoo/D0MQeGJggrbjS1D66zek88/0rDRqcUOf0DKN6B2JAK6ihmwNVlOyM/qoCcenD
 nV/A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:mime-version:date:message-id:subject:to
 :content-transfer-encoding;
 bh=MwXJyW1smoQSmWW0cRiq68GDc69dgK7Aad6tCkM95Sc=;
 b=Qp7ptAodmpVa2+47iG5TiiQcsyJru3YyL85UXEciNaYNBFq8GX02TJfscT5L2/7dYB
 1JBBT+JYoXnlbJPgXE6wi0LWTwJjl9p5X1mkl0ZsY3R+hbbY43sUsF1i01k5IqbKc+jQ
 VibtUuCMc44deBPEtcW/BBM2JhRk3qYXpBHJrgWCE9wxr2PBcEFygmixwRTA5EGAaY/U
 gqA4Kc6gJOgrYx3tYFyoucIfKuXv+NKxYN2x9Ts9HLh5E5FA1ttiaVGI9QD05wtbIpqP
 wKauSDUHjLnFvlTY5d+UuXkzrZMBPJQ2a31gNXPbf6GLEBtjaZ0dYpsX/R6kpP46xqXu
 e3FA==
X-Gm-Message-State: AJcUukccwGyxZs8USWpV1v1shODTtRvf4DqUQq1wqq791dwAgu8zLui8
 epbhTp8SswOICeaKUAcHv1WfX/drSY1gMlVZ3hwG8A==
X-Google-Smtp-Source: ALg8bN46Qz8LySNguxArxZcvOQ0s449Up58knvlit5f8q2kL7HnHFFF6wcWEn3NxKKHLMtkAl45F8XALvoklmZtO/HA=
X-Received: by 2002:a25:98c4:: with SMTP id m4mr11294967ybo.214.1545902940163; 
 Thu, 27 Dec 2018 01:29:00 -0800 (PST)
Received: from 1058052472880 named unknown by gmailapi.google.com with
 HTTPREST; Thu, 27 Dec 2018 04:28:59 -0500
From: Quek Yu Han <qythium@HIDDEN>
MIME-Version: 1.0
Date: Thu, 27 Dec 2018 04:28:59 -0500
Message-ID: <CAGCUw0jQX_rp7ZhmFr4FLUmH0BUzeR48MObuFR-CHX5LsuTMvA@HIDDEN>
Subject: 27.0.50; Incorrect behaviour of cl-loop macro
To: bug-gnu-emacs@HIDDEN
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2607:f8b0:4864:20::b30
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 27 Dec 2018 12:36:33 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

It appears that a change to the `cl-loop` macro in Emacs 27 introduced a
bug where certain clauses would be evaluated more than once in a loop
with a "when" clause.

See the following minimal example which finds the index of an element in
a list:


(cl-loop
=C2=A0for x in '(a b c d e)
=C2=A0for index =3D 0 then (1+ index)
=C2=A0when (eq x 'e)
=C2=A0return index)


In Emacs 26.1 this returns `4` as expected, but in Emacs 27.0.50 it
returns `7`, due to the index being incremented twice per loop. The same
occurs after a `emacs -Q` restart.

For reference here is the macroexpanded form of the above expression,
with the difference between 26 and 27 outlined (everything else is
identical):


(cl-block nil
=C2=A0 (let* ((--cl-var-- '(a b c d e))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(x nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(index nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(--cl-var-- t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(--cl-var-- t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0--cl-var--)
=C2=A0 =C2=A0 (while (and (consp --cl-var--)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq x (car=
 --cl-var--))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq index
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 (if --cl-var-- 0 (1+ index)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (eq x 'e=
)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 (setq --cl-var-- index
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 --cl-var-- nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t)))
=C2=A0 =C2=A0 =C2=A0 (setq --cl-var-- (cdr --cl-var--))

;;;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ADDED IN EMACS 27 =3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=C2=A0 =C2=A0 =C2=A0 (and (and (consp --cl-var--)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq x (car=
 --cl-var--))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq index
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 (if --cl-var-- 0 (1+ index)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (eq x 'e=
)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 (setq --cl-var-- index
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 --cl-var-- nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t))))
;;;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D

=C2=A0 =C2=A0 =C2=A0 (setq --cl-var-- nil))
=C2=A0 =C2=A0 --cl-var--))



Thanks!





In GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin17.6.0, NS
appkit-1561.40 Version 10.13.5 (Build 17F77))
=C2=A0of 2018-07-08 built on QYH.local
Repository revision: 98463bed07ecc9057094928ffdc2321eaaf3ab52
Windowing system distributor 'Apple', version 10.3.1671
System Description: =C2=A0Mac OS X 10.14.2

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Configured using:
=C2=A0'configure --disable-dependency-tracking --disable-silent-rules
=C2=A0--enable-locallisppath=3D/usr/local/share/emacs/site-lisp
=C2=A0--infodir=3D/usr/local/Cellar/emacs-plus/HEAD-98463be/share/info/emac=
s
=C2=A0--prefix=3D/usr/local/Cellar/emacs-plus/HEAD-98463be --with-xml2
=C2=A0--without-dbus --with-gnutls --with-imagemagick --with-modules
=C2=A0--with-rsvg --with-xwidgets --with-ns --disable-ns-self-contained'

Configured features:
RSVG IMAGEMAGICK NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS
MODULES THREADS XWIDGETS LCMS2

Important settings:
=C2=A0 value of $LC_ALL: en_US.UTF-8
=C2=A0 value of $LC_CTYPE: UTF-8
=C2=A0 value of $LANG: en_US.UTF-8
=C2=A0 locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
=C2=A0 tooltip-mode: t
=C2=A0 global-eldoc-mode: t
=C2=A0 eldoc-mode: t
=C2=A0 electric-indent-mode: t
=C2=A0 mouse-wheel-mode: t
=C2=A0 tool-bar-mode: t
=C2=A0 menu-bar-mode: t
=C2=A0 file-name-shadow-mode: t
=C2=A0 global-font-lock-mode: t
=C2=A0 font-lock-mode: t
=C2=A0 blink-cursor-mode: t
=C2=A0 auto-composition-mode: t
=C2=A0 auto-encryption-mode: t
=C2=A0 auto-compression-mode: t
=C2=A0 line-number-mode: t
=C2=A0 transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv dired dired-loaddefs format-spec rfc822 mml
easymenu mml-sec password-cache epa derived epg epg-config gnus-util
rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair time-date
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core term/tty-colors frame cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote xwidget-internal kqueue
cocoa ns lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 203880 9574)
=C2=A0(symbols 48 20001 1)
=C2=A0(miscs 40 33 114)
=C2=A0(strings 32 28869 1418)
=C2=A0(string-bytes 1 768776)
=C2=A0(vectors 16 35252)
=C2=A0(vector-slots 8 725502 18860)
=C2=A0(floats 8 47 69)
=C2=A0(intervals 56 230 0)
=C2=A0(buffers 992 11))




Acknowledgement sent to Quek Yu Han <qythium@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#33890; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 31 Dec 2018 06:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.