GNU bug report logs - #49749
26.3; 26.3 & 27.2: invalid byte compiler warning in short-circuited or form

Previous Next

Package: emacs;

Reported by: Pierre Rouleau <prouleau001 <at> gmail.com>

Date: Tue, 27 Jul 2021 18:55:02 UTC

Severity: wishlist

Tags: moreinfo, notabug

Found in version 26.3

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Pierre Rouleau <prouleau001 <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 49749 <at> debbugs.gnu.org
Subject: Re: bug#49749: 26.3; 26.3 & 27.2: invalid byte compiler warning in
 short-circuited or form
Date: Sun, 01 Aug 2021 02:19:23 +0200
Pierre Rouleau <prouleau001 <at> gmail.com> writes:

> On Wed, Jul 28, 2021 at 11:26 AM Lars Ingebrigtsen <larsi <at> gnus.org> wrote:
>
>  Pierre Rouleau <prouleau001 <at> gmail.com> writes:
>
>  > (defun f-or ()
>  >   "Use or."
>  >   (when (or (null (boundp 'foo))
>  >             (null foo))  ;=> ``Warning: reference to free variable ‘foo’``                         
>  >     (message "foo is not set")))

> Well, from the perspective of a user, that would look at the 
> very least as a technical limitation.

There are a lot of possible expressions of the form

 (some-expression-involving-both (boundp 'foo) foo)

You have showed two.  There is an unlimited number of such expressions,
and it's impossible to solve the problem for all of them.  It's not hard
to support more, but for what gain?  The warning is still correct -
there _is_ a reference to a free variable.  It doesn't say "unbound".

When your reference to a free variable is not totally trivial, the
common method is to add a

  (defvar foo)

to your code.  That tells you and other readers and the compiler that
`foo' is a special variable defined elsewhere, and the warning is also
gone.

Also, (and (boundp 'foo) foo) is equivalent to (bound-and-true-p foo),
so there is a canonical form for that kind of test that doesn't lead to
a warning.  For more complex real-life situations, you will probably
need a `defvar' anyway, so we are really only discussing about
rewritings of `bound-and-true-p' using De Morgan rules.  I agree to Lars
that this would not be a useful thing to do.

Michael.




This bug report was last modified 3 years and 356 days ago.

Previous Next


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