bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar.


From: Stefan Monnier
Subject: bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar.
Date: Mon, 07 Nov 2022 08:07:28 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> (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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]