bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#28107: 26.0.50; Byte compilation shows an unused var warning for an


From: Glenn Morris
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
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]