Subject: Re: bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable

From: Glenn Morris <[email-masked]>
Date: Thu, 17 Aug 2017 12:39:58 -0400

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.