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

From: Pierre Rouleau <[email-masked]>
Date: Sat, 31 Jul 2021 09:59:02 -0400

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")))
>
> The message about invalid stuff is only discarded if Emacs is trivially
> able to deduce that it'll never be evaluated -- and as you've found out,
> it's easy to make that heuristic not be heeded (see
> `byte-compile-maybe-guarded' for details).
>

Thanks.  I must admit I do not know the byte compiler code much at this
point.

> So I'm not sure this is a bug -- Emacs can't determine all cases where
> we won't be executing the code in question at compile time.
>

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

The byte compiler is able to report unused lexical variables.
It's able to report access to unbound symbols in a large
number of code patterns.  That helps detect a lot of coding mistakes
and that's very valuable.

It may be difficult, or perhaps even not possible, to prevent the warning
in the situation I reported.  If the byte compiler cannot be improve to
handle
this situation, could this scenario be added to the list of know limitations
of the byte-compiler?  Maybe someday it will become possible to handle it
and this scenario will help the process?

-- 
/Pierre