Subject: bug#28990: 27.0.50; thunk-delay: running expansion also requires lexical-binding

From: Michael Heerdegen <[email-masked]>
Date: Fri, 27 Oct 2017 16:08:12 +0200

Michael Heerdegen <[email-masked]> writes:

> #+begin_src emacs-lisp
> (defun my-thunk-test ()
>   (thunk-force (thunk-delay (+ 1 2))))
> #+end_src
>
> This compiles ok, but executing (my-thunk-test) without lexbind enabled
> gives you a meaningless error like "void-variable: forced".

Nicolas, Stefan - ok to fix it like that?

>From 45fe6b1bc9573257e59842283fd7da36d760c524 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <[email-masked]>
Date: Thu, 26 Oct 2017 12:57:55 +0200
Subject: [PATCH] WIP: Fix bug#28990

---
 lisp/emacs-lisp/thunk.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/emacs-lisp/thunk.el b/lisp/emacs-lisp/thunk.el
index bb6d277c27..6dc892c44b 100644
--- a/lisp/emacs-lisp/thunk.el
+++ b/lisp/emacs-lisp/thunk.el
@@ -44,9 +44,12 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-macs))
+
 (defmacro thunk-delay (&rest body)
   "Delay the evaluation of BODY."
   (declare (debug t))
+  (cl-assert lexical-binding)
   (let ((forced (make-symbol "forced"))
         (val (make-symbol "val")))
     `(let (,forced ,val)
-- 
2.14.2

I would additionally add a sentence to "thunk.el"'s header saying that
creating thunks requires lexical binding.

TIA,

Michael.