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


Message #14 received at 59057 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 59057 <at> debbugs.gnu.org
Subject: Re: bug#59057: Emacs 29.  Byte compiler sometimes forgets about a
 defvar.
Date: Mon, 07 Nov 2022 16:29:15 -0500
>> (defvar VAR) does not "create a variable".
>
> According to both its doc string and the Elisp manual it does.

Where?  I'm talking specifically about (defvar VAR) not about
`defvar` in general.

>> It just "locally" declares that this identifier should use dynamic
>> scoping when binding a variable.
> Why "locally"?  There's just one obarray involved, which is global.

No, we want to allow `defvar` to have a lexically-local effect.

>> 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)))))
>
> There are workarounds, yes.  But surely it would be better to fix the
> bug.

It's not a workaround.  It's how the programmers say whether they want
the (defvar ,var) declaration to affect all the rest of the code or only
the code within the `when`.

Why put the (defvar ,var) within the `when` if not to limit
its scope?


        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.