1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 14:30:50 -08:00
emacs/test/lisp/emacs-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
..
edebug-resources Update copyright year to 2018 2018-01-01 00:57:59 -08:00
eieio-tests Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
faceup-resources Update copyright year to 2018 2018-01-01 01:25:56 -08:00
faceup-tests Update copyright year to 2018 2018-01-01 01:25:56 -08:00
package-resources Don't use IP 0.0.0.0 for package test server (Bug#22582) 2017-02-25 12:56:09 -05:00
testcover-resources Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
benchmark-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
bytecomp-tests.el ; Adapt a unit test to a recent change 2018-01-07 16:47:17 +01:00
checkdoc-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
cl-extra-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
cl-generic-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
cl-lib-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
cl-macs-tests.el cl-loop: Add missing guard condition 2018-01-08 19:15:28 +09:00
cl-print-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
cl-seq-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
derived-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
edebug-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ert-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ert-x-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
generator-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
gv-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
let-alist-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
lisp-mode-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
lisp-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
map-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
nadvice-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
package-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
pcase-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
pp-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
regexp-opt-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
ring-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
rmc-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
rx-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
seq-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
subr-x-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
tabulated-list-test.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00
testcover-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
thunk-tests.el Merge from origin/emacs-26 2018-01-01 01:13:04 -08:00
timer-tests.el Update copyright year to 2018 2018-01-01 00:57:59 -08:00