GNU bug report logs -
#28107
26.0.50; Byte compilation shows an unused var warning for an used variable
Previous Next
Reported by: Tino Calancha <tino.calancha <at> gmail.com>
Date: Wed, 16 Aug 2017 06:13:02 UTC
Severity: minor
Tags: notabug
Found in version 26.0.50
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 28107 <at> debbugs.gnu.org (full text, mbox):
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.
This bug report was last modified 5 years and 350 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.