Subject: Re: bug#49749: 26.3; 26.3 & 27.2: invalid byte compiler warning in short-circuited or form

From: Michael Heerdegen <[email-masked]>
Date: Sun, 01 Aug 2021 02:19:23 +0200

Pierre Rouleau <[email-masked]> writes:

> On Wed, Jul 28, 2021 at 11:26 AM Lars Ingebrigtsen <[email-masked]> wrote:
>
>  Pierre Rouleau <[email-masked]> 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.