1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-31 17:30:54 -08:00
emacs/test/lisp
Tino Calancha a0365437c9 cl-loop: Add missing guard condition
Consider the expansion of `cl-loop' with a `for' clause and more
than one internal variables, X, Y, processed in parallel.
Each step updates X and Y right after update the loop variable, K; if
either X or Y depend on K, then some forms of the body are
evaluated with the wrong K (Bug#29799).

For instance, consider the following code:
(cl-loop for k below 2
         for x = (progn (message "k = %d" k) 1)
         and y = 1)

This code should show in *Messages*:
k = 0
k = 1

Instead, the code shows:
k = 0
k = 1
k = 2

To prevent this we must ensure that the loop condition is still
satisfied right after update the loop variable.
In the macro expansion of the example above, right after:
(setq k (+ k 1))

evaluate the rest of the body forms iif the condition
(< k 2)
is still valid.

* lisp/emacs-lisp/cl-macs.el (cl--loop-guard-cond): New variable.
(cl--parse-loop-clause): Set it non-nil if the loop contains
a for/as clause.
(cl-loop): After update the loop variable, evaluate the remaining of
the body forms just if the loop condition is still valid (Bug#29799).

* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-for-as-equals-and):
New test.
2018-01-08 19:15:28 +09:00
..
calc Update copyright year to 2018 2018-01-01 00:57:59 -08:00
calendar Update copyright year to 2018 2018-01-01 00:57:59 -08:00
emacs-lisp cl-loop: Add missing guard condition 2018-01-08 19:15:28 +09:00
emulation Update copyright year to 2018 2018-01-01 00:57:59 -08:00
erc Update copyright year to 2018 2018-01-01 00:57:59 -08:00
eshell Update copyright year to 2018 2018-01-01 00:57:59 -08:00
gnus Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
international Update copyright year to 2018 2018-01-01 00:57:59 -08:00
mail Update copyright year to 2018 2018-01-01 00:57:59 -08:00
net Make tramp-tests.el more robust on w32 2018-01-07 18:50:06 +01:00
progmodes Update copyright year to 2018 2018-01-01 00:57:59 -08:00
textmodes Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
url Update copyright year to 2018 2018-01-01 00:57:59 -08:00
vc Fix copyright years by hand 2018-01-01 01:02:09 -08:00
abbrev-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
arc-mode-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
auth-source-pass-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
auth-source-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
autorevert-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
buff-menu-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
char-fold-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
color-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
comint-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
dabbrev-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
descr-text-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
dired-aux-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
dired-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
dired-x-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
dom-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
electric-tests.el Ignore escape characters for context-sensitive quotes (Bug#29812) 2018-01-07 13:52:59 +01:00
epg-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
faces-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ffap-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
filenotify-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
files-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
files-x-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
help-fns-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
hi-lock-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
htmlfontify-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
ibuffer-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ido-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
imenu-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
info-xref-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
isearch-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
jit-lock-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
json-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
kmacro-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ls-lisp-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
man-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
md4-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
minibuffer-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
mouse-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
obarray-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ps-print-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
register-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
replace-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
rot13-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ses-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
shell-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
simple-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
sort-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
soundex-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
subr-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
tar-mode-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
thingatpt-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
whitespace-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
xdg-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
xml-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
xt-mouse-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00