all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
@ 2017-08-16  6:11 Tino Calancha
  2017-08-17 16:39 ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Tino Calancha @ 2017-08-16  6:11 UTC (permalink / raw)
  To: 28107


Write a file '/tmp/test.el' with following content:
--8<-----------------------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-

;; Compiles OK
(defun test ()
  (let ((lst (list "foo" 1)))
    (when (cdr lst)
      (equal (cdr lst) 1))))

;; 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))))))

;; 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))))))

--8<-----------------------------cut here---------------end--------------->8---

emacs -Q
M-x byte-compile-file /tmp/test.el RET
I got a warning from test2 func:
Warning: value returned from (cdr x) is unused

But the value is used as the `when' condition, and as `equal'
1st argument.


In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-08-16
Repository revision: 3305dec5387021791eb09a93df5ab784b2297dc8






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
  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
  2017-08-17 16:45   ` Glenn Morris
  2017-08-17 17:32   ` Tino Calancha
  0 siblings, 2 replies; 6+ messages in thread
From: Glenn Morris @ 2017-08-17 16:39 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 28107

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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
  2017-08-17 16:39 ` Glenn Morris
@ 2017-08-17 16:45   ` Glenn Morris
  2017-08-17 17:32   ` Tino Calancha
  1 sibling, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2017-08-17 16:45 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 28107

Glenn Morris wrote:

> If getcdr is known to be side-effect-free, you get the same warning.

s/getcdr/getval





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
  2017-08-17 16:39 ` Glenn Morris
  2017-08-17 16:45   ` Glenn Morris
@ 2017-08-17 17:32   ` Tino Calancha
  2017-08-18  1:42     ` Glenn Morris
  1 sibling, 1 reply; 6+ messages in thread
From: Tino Calancha @ 2017-08-17 17:32 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 28107, Tino Calancha



On Thu, 17 Aug 2017, Glenn Morris wrote:

> 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.
Even without the dolist we get such warning:
$> cat /tmp/test.el
;; -*- lexical-binding: t; -*-
(let ((x 1))
   (and (equal (+ x 2) 3)))

M-x byte-compile-file RET /tmp/test RET
Compiling file /tmp/test.el at Fri Aug 18 02:30:59 2017
test.el:2:1:Warning: value returned from (+ x 2) is unused
test.el:2:1:Warning: value returned from (+ x 2) is unused

I used (+ x 2) as 1st argument for `equal'.  What more should i do to
use it? Maybe invite (+ x 2) to the cinema?
I hope (+ x 2) will pay, cinema it's too expensive here.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
  2017-08-17 17:32   ` Tino Calancha
@ 2017-08-18  1:42     ` Glenn Morris
  2019-06-12 15:03       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2017-08-18  1:42 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 28107

Tino Calancha wrote:

> ;; -*- lexical-binding: t; -*-
> (let ((x 1))
>   (and (equal (+ x 2) 3)))

This code also does nothing. Compare with:

(defun foo ()
  (let ((x 1))
   (and (equal (+ x 2) 3))))

where the result is used (as the function return) and there is no warning.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#28107: 26.0.50; Byte compilation shows an unused var warning for an used variable
  2017-08-18  1:42     ` Glenn Morris
@ 2019-06-12 15:03       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-12 15:03 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 28107, Tino Calancha

Glenn Morris <rgm@gnu.org> writes:

> Tino Calancha wrote:
>
>> ;; -*- lexical-binding: t; -*-
>> (let ((x 1))
>>   (and (equal (+ x 2) 3)))
>
> This code also does nothing. Compare with:
>
> (defun foo ()
>   (let ((x 1))
>    (and (equal (+ x 2) 3))))
>
> where the result is used (as the function return) and there is no warning.

So I don't think there's a bug here, and I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-12 15:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.