From: Glenn Morris <rgm@gnu.org>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: 28107@debbugs.gnu.org
Subject: bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
Date: Thu, 17 Aug 2017 12:39:58 -0400 [thread overview]
Message-ID: <fv1soa6tcx.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <87d17wyrbw.fsf@calancha-pc> (Tino Calancha's message of "Wed, 16 Aug 2017 15:11:47 +0900")
Tino Calancha wrote:
> ;; Warning: value returned from (cdr x) is unused
> (defun test2 ()
> (let ((alist (list (cons "foo" 1) (cons "bar" 2))))
> (dolist (x alist)
> (when (cdr x)
> (equal (cdr x) (alist-get (car x) alist))))))
Isn't this function a no-op?
Eg dolist does not return the last value from the body.
So a smaller example of the same thing is:
(dolist (x '(1))
(equal (+ x 2) 3))
which returns nil.
> ;; Compiles OK
> (defun getval (x) (cdr x))
> (defun test3 ()
> (let ((alist (list (cons "foo" 1) (cons "bar" 2))))
> (dolist (x alist)
> (when (getval x)
> (equal (getval x) (alist-get (car x) alist))))))
If getcdr is known to be side-effect-free, you get the same warning.
(eval-when-compile
(put 'getcdr 'side-effect-free t))
So I think this is a (slightly inaccurate) warning of a real issue.
next prev parent reply other threads:[~2017-08-17 16:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-16 6:11 bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable Tino Calancha
2017-08-17 16:39 ` Glenn Morris [this message]
2017-08-17 16:45 ` Glenn Morris
2017-08-17 17:32 ` Tino Calancha
2017-08-18 1:42 ` Glenn Morris
2019-06-12 15:03 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fv1soa6tcx.fsf@fencepost.gnu.org \
--to=rgm@gnu.org \
--cc=28107@debbugs.gnu.org \
--cc=tino.calancha@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.