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

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

bug#49749: 26.3; 26.3 & 27.2: invalid byte compiler warning in short-cir


From: Michael Heerdegen
Subject: 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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Pierre Rouleau <prouleau001@gmail.com> writes:

> On Wed, Jul 28, 2021 at 11:26 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
>  Pierre Rouleau <prouleau001@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.





reply via email to

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