Subject: Re: bug#51982: Erroneous handling of local variables in byte-compiled nested lambdas

From: Michael Heerdegen <[email-masked]>
Date: Sat, 20 Nov 2021 05:44:38 +0100

Hello Paul,

thanks for the report, I can reproduce the issue, there is something
going wrong when compiling.  I guess this is something for Mattias or
Stefan maybe? (CC'd)

#+begin_src emacs-lisp
; -*- lexical-binding: t -*-

(defun wtf (x)
  (let ((it 0))
    #'(lambda ()
        (let ((fn #'(lambda () it)))
          (if x
              (let ((it x))
                it)
            (funcall fn))))))
#+end_src

Byte compile:

>     wtf.el:9:17:Warning: reference to free variable ‘it’

(funcall (wtf 1))

>     Symbol’s value as variable is void: it

while expected result is 1.  Uncompiled code works as expected.

TIA,

Michael.