unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Pierre Rouleau <prouleau001@gmail.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 49749@debbugs.gnu.org
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	[thread overview]
Message-ID: <87r1fe9fuc.fsf@web.de> (raw)
In-Reply-To: <CALTqLiZYoYCfFXdAX6b8SzA9rPDyp61B7RNy7r-=5jc8P+Z_Og@mail.gmail.com> (Pierre Rouleau's message of "Sat, 31 Jul 2021 09:59:02 -0400")

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	other threads:[~2021-08-01  0:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 18:54 bug#49749: 26.3; 26.3 & 27.2: invalid byte compiler warning in short-circuited or form Pierre Rouleau
2021-07-28 15:26 ` Lars Ingebrigtsen
2021-07-31 13:59   ` Pierre Rouleau
2021-08-01  0:19     ` Michael Heerdegen [this message]
2021-08-01 10:26       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1fe9fuc.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=49749@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=prouleau001@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).