GNU bug report logs - #28107
26.0.50; Byte compilation shows an unused var warning for an used variable

Previous Next

Package: emacs;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 28107 in the body.
You can then email your comments to 28107 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Wed, 16 Aug 2017 06:13:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <tino.calancha <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 16 Aug 2017 06:13:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50;
 Byte compilation shows an unused var warning for an used variable
Date: Wed, 16 Aug 2017 15:11:47 +0900
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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Thu, 17 Aug 2017 16:41:01 GMT) Full text and rfc822 format available.

Message #8 received at 28107 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 28107 <at> debbugs.gnu.org
Subject: Re: 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
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Thu, 17 Aug 2017 16:46:02 GMT) Full text and rfc822 format available.

Message #11 received at 28107 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 28107 <at> debbugs.gnu.org
Subject: Re: bug#28107: 26.0.50;
 Byte compilation shows an unused var warning for an used variable
Date: Thu, 17 Aug 2017 12:45:40 -0400
Glenn Morris wrote:

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

s/getcdr/getval




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Thu, 17 Aug 2017 17:34:02 GMT) Full text and rfc822 format available.

Message #14 received at 28107 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 28107 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#28107: 26.0.50; Byte compilation shows an unused var warning
 for an used variable
Date: Fri, 18 Aug 2017 02:32:59 +0900 (JST)

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Fri, 18 Aug 2017 01:43:02 GMT) Full text and rfc822 format available.

Message #17 received at 28107 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 28107 <at> debbugs.gnu.org
Subject: Re: bug#28107: 26.0.50;
 Byte compilation shows an unused var warning for an used variable
Date: Thu, 17 Aug 2017 21:42:32 -0400
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#28107; Package emacs. (Wed, 12 Jun 2019 15:04:02 GMT) Full text and rfc822 format available.

Message #20 received at 28107 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 28107 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#28107: 26.0.50;
 Byte compilation shows an unused var warning for an used variable
Date: Wed, 12 Jun 2019 17:03:45 +0200
Glenn Morris <rgm <at> 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




Added tag(s) notabug. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 12 Jun 2019 15:04:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 28107 <at> debbugs.gnu.org and Tino Calancha <tino.calancha <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 12 Jun 2019 15:04:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 11 Jul 2019 11:24:04 GMT) Full text and rfc822 format available.

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.