GNU bug report logs - #60315
28.2; Byte-compiler warning for free variable

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sun, 25 Dec 2022 17:09:02 UTC

Severity: wishlist

Found in version 28.2

To reply to this bug, email your comments to 60315 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#60315; Package emacs. (Sun, 25 Dec 2022 17:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 25 Dec 2022 17:09:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: 28.2; Byte-compiler warning for free variable
Date: Sun, 25 Dec 2022 17:07:55 +0000
You might not consider this a bug, or you might consider it not worth
trying to fix.  That's fine by me.  I think it's worth reporting, at
least.  Maybe something can be done for it, or maybe you can let me know
a good way to work around it.

Unlike `defvar', `defconst', alters the value each time it's evaluated.
E.g., if you load a file with (defconst foo bar "...") more than once
then the value of `foo' gets set each time to whatever is the current
value of `bar'.  That's normal and desirable (and consistent with other
Lisps, such as CL).

How to ensure that a defconst sets the value only once, when the file
it's in is loaded?  A defvar does that, but a defconst does not.

Maybe there's a better way, but I've been using this so far:

  (unless (boundp 'foo) (defconst foo bar "..."))

But that results in this byte-compiler warning:

 In blah-fun:
 toto.el:236:34:Warning: reference to free variable
     `foo'

An alternative is to use a defvar and just say in its doc string that
it's intended as a constant (don't set it etc.).  Maybe that's less
confusing to users than seeing the warning?  Dunno.

In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
 of 2022-09-13 built on AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19044
System Description: Microsoft Windows 10 Pro (v10.0.2009.19044.2364)

Configured using:
 'configure --with-modules --without-dbus --with-native-compilation
 --without-compress-install CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
XPM ZLIB

(NATIVE_COMP present but libgccjit not available)





Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Sep 2023 15:05:01 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 283 days ago.

Previous Next


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