From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 13814@debbugs.gnu.org, Jorgen Schaefer <forcer@forcix.cx>
Subject: bug#13814: 24.3.50; Dynamic variables shadowing prevent defvar
Date: Tue, 24 Aug 2021 17:25:33 -0400 [thread overview]
Message-ID: <jwv4kbeh7d9.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87y28tt0q1.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 23 Aug 2021 03:21:26 +0200")
Lars Ingebrigtsen [2021-08-23 03:21:26] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Thanks for filing it, so we have a clear bug-number for this long
>> standing problem. If someone wants to take a crack at fixing it,
>> I think that we should add a `set-toplevel-default' which defvar and
>> defcustom could use, as for how to implement it, I you can take a look
>> at the check&warning in the C code of `defvar'.
FWIW, this bug was presumably fixed with:
commit a104f656c8217b027866d32e8d7bf024a671e3cc
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Fri Aug 2 17:16:33 2013 -0400
So we should probably close it.
> When running this from M-: now, I get the following backtrace:
>
> Debugger entered--Lisp error: (error "Defining as dynamic an already lexical var")
> (defvar bug-variable t "This variable is not defined when autoloaded.")
> eval-buffer(#<buffer *load*> nil "/tmp/bug-lib.el" nil t) ; Reading at buffer position 74
> load-with-code-conversion("/tmp/bug-lib.el" "/tmp/bug-lib.el" nil t)
> (bug-variable-value)
> (let ((bug-variable nil)) (bug-variable-value))
> eval((let ((bug-variable nil)) (bug-variable-value)) t)
> eval-expression((let ((bug-variable nil)) (bug-variable-value)) nil nil 127)
> funcall-interactively(eval-expression (let ((bug-variable nil)) (bug-variable-value)) nil nil 127)
> call-interactively(eval-expression nil nil)
>
> So this signals an error when doing the
>
> (let ((bug-variable nil))
> (bug-variable-value))
>
> from a lexical context.
Yes, this is a new feature: when we get to the `defvar` the problem is
not just that we need to "punch through" and define the toplevel/dynamic
value of `bug-variable` but also that the `let` would need to be
retroactively changed to be dynamic, which would in general require
time-travel, hence the error.
The fix is to use another var name (if you do want your `let` to be
statically scoped) or to use `dlet`, or an explicit `defvar`, or an
explicit `(require 'bug-lib)`, ...
Stefan
next prev parent reply other threads:[~2021-08-24 21:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 19:30 bug#13814: 24.3.50; Dynamic variables shadowing prevent defvar Jorgen Schaefer
2013-02-25 23:15 ` Glenn Morris
2013-02-26 0:03 ` Stefan Monnier
2021-08-23 1:21 ` Lars Ingebrigtsen
2021-08-24 21:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-08-25 11:00 ` Lars Ingebrigtsen
2021-08-25 14:41 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-25 16:03 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv4kbeh7d9.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=13814@debbugs.gnu.org \
--cc=forcer@forcix.cx \
--cc=larsi@gnus.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).