GNU bug report logs - #59057
Emacs 29. Byte compiler sometimes forgets about a defvar.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Sat, 5 Nov 2022 18:47:02 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 59057 <at> debbugs.gnu.org
Subject: bug#59057: Emacs 29.  Byte compiler sometimes forgets about a defvar.
Date: Mon, 07 Nov 2022 08:07:28 -0500
> (defmacro acm-defvar (var)
>   `(eval-when-compile
> ;     (when (version-check)
>        (defvar ,var)
>        (setq ,var emacs-major-version)
> ;       )
>      ))

(defvar VAR) does not "create a variable".  It just "locally" declares
that this identifier should use dynamic scoping when binding a variable.

Before the commit you mentioned, the above (defvar ,var) would sometimes
incorrectly escape its `when` subexpression and affect subsequent code,
which is why in the past the presence of `when` did not make much
difference whereas it now does.

Note also that for the same reason the above should arguably never work
at all since the effect of (defvar ,var) should not escape the
`eval-when-compile` subexpression.  A lot of code relies on this
misbehavior, tho, so we still support it.  But the better way to write
the above code is:

    (defmacro acm-defvar (var)
      `(progn
         (defvar ,var)
         (eval-when-compile
           (when (version-check)
             (setq ,var emacs-major-version)))))

> This bug doesn't occur on Emacs 28.
> I have a feeling it was introduced into Emacs 29 very recently.

The Emacs-28 behavior was a misbehavior, which got fixed accidentally
recently :-)


        Stefan





This bug report was last modified 2 years and 261 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.