summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/cl-macs-tests.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2021-12-20 11:59:22 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2021-12-20 16:26:02 +0100
commit92ffe44834b8f77ee3f4d37edfdb19f30a376869 (patch)
tree505872b790d2b6799d4b26a34187ca834d3a4475 /test/lisp/emacs-lisp/cl-macs-tests.el
parent8706f6fde13729bf330693cfd163773583e526a9 (diff)
downloademacs-92ffe44834b8f77ee3f4d37edfdb19f30a376869.tar.gz
Body of dynamic let-bindings is not in tail position
This fixes a known bug in `named-let`. * lisp/emacs-lisp/cl-macs.el (cl--self-tco): Prevent TCO from inside dynamic variable bindings. * test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs--labels): Add test.
Diffstat (limited to 'test/lisp/emacs-lisp/cl-macs-tests.el')
-rw-r--r--test/lisp/emacs-lisp/cl-macs-tests.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el
index 13da60ec45e..ced2cc10f30 100644
--- a/test/lisp/emacs-lisp/cl-macs-tests.el
+++ b/test/lisp/emacs-lisp/cl-macs-tests.el
@@ -666,7 +666,24 @@ collection clause."
(should (pcase (macroexpand
'(cl-labels ((len (xs n) (if xs (len (cdr xs) (1+ n)) n)))
#'len))
- (`(function (lambda (,_ ,_) . ,_)) t))))
+ (`(function (lambda (,_ ,_) . ,_)) t)))
+
+ ;; Verify that there is no tail position inside dynamic variable bindings.
+ (defvar dyn-var)
+ (let ((dyn-var 'a))
+ (cl-labels ((f (x) (if x
+ dyn-var
+ (let ((dyn-var 'b))
+ (f dyn-var)))))
+ (should (equal (f nil) 'b))))
+
+ ;; Control: same as above but with lexical binding.
+ (let ((lex-var 'a))
+ (cl-labels ((f (x) (if x
+ lex-var
+ (let ((lex-var 'b))
+ (f lex-var)))))
+ (should (equal (f nil) 'a)))))
(ert-deftest cl-macs--progv ()
(defvar cl-macs--test)