GNU bug report logs - #21185
25.0.50; byte-compiler warn on quote lexical var

Previous Next

Package: emacs;

Reported by: stephen_leake <at> stephe-leake.org

Date: Tue, 4 Aug 2015 09:18:02 UTC

Severity: minor

Tags: wontfix

Found in version 25.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 21185 in the body.
You can then email your comments to 21185 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#21185; Package emacs. (Tue, 04 Aug 2015 09:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to stephen_leake <at> stephe-leake.org:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 04 Aug 2015 09:18:02 GMT) Full text and rfc822 format available.

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

From: stephen_leake <at> stephe-leake.org
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; byte-compiler warn on quote lexical var
Date: Tue, 04 Aug 2015 04:17:21 -0500
This file gives an example where a new byte-compiler warning would be
useful:

;; quote-lexical-var.el -*- lexical-binding: t -*-

(defun display-var (var)
  "Display variable value of VAR (a symbol), if any."
  (cond
   ((boundp var)
    (message "%s: %s" (symbol-name var) (symbol-value var)))

   (t
    (message "%s not bound" (symbol-name var)))))

(defun quote-lexical-var ()
  (let ((my-var "foo"))
    (message "non-quoted my-var: %s" my-var)
    (display-var 'my-var)))

(provide 'quote-lexical-var)
;; end of file

To see the problem, execute (in emacs master, -Q):

    (add-to-list 'load-path "/home/stephe/Elisp_Work/")
    ;; path containing above file

    (byte-compile-file  "/home/stephe/Elisp_Work/quote-lexical-var.el")
    (require 'quote-lexical-var)

    (display-var 'default-directory)

This gives "default-directory: /home/stephe" as expected.

    (quote-lexical-var)

This gives:

non-quoted my-var: foo
my-var: not bound

Quoting lexical variables does not work; there is no symbol available at
run-time.

I've been bitten by this problem when converting code to use lexical
binding; it would be helpful if the byte-compiler warned about it.


In GNU Emacs 25.0.50.4 (x86_64-w64-mingw32)
 of 2015-08-02 on TAKVER2
Repository revision: d2c4309d46529bac656f332677d2c5e199577845
Windowing system distributor `Microsoft Corp.', version 6.3.9600
Configured using:
 `configure --prefix=/mingw64
 PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: cp1252

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns help-mode easymenu cl-loaddefs pcase cl-lib mail-prsvr
mail-utils time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote w32notify w32 multi-tty
make-network-process emacs)

Memory information:
((conses 16 82209 4908)
 (symbols 56 18803 0)
 (miscs 48 36 106)
 (strings 32 14166 4682)
 (string-bytes 1 381142)
 (vectors 16 10489)
 (vector-slots 8 395072 6302)
 (floats 8 121 16)
 (intervals 56 221 2)
 (buffers 976 11))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21185; Package emacs. (Thu, 06 Aug 2015 03:29:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: stephen_leake <at> stephe-leake.org
Cc: 21185 <at> debbugs.gnu.org
Subject: Re: bug#21185: 25.0.50; byte-compiler warn on quote lexical var
Date: Wed, 05 Aug 2015 23:28:52 -0400
> I've been bitten by this problem when converting code to use lexical
> binding; it would be helpful if the byte-compiler warned about it.

Agreed, but I haven't figured out how to make this work.
There are two problems:
1- detect not just things like « 'var » but also things like « '(var1
   var2 var3) » since such occur in a few places as well.
2- don't swamp the user with false positives.

Problem 2 is by far the biggest.  It's very common to have a local
variable `face' and at the same time to use the symbol `face' (quoted),
for example.

I do have such a warning in my local hacks (it outputs a warning for any
'<var> where <var> is a locally bound lexical variable) and find it
unbearable, even though I'm usually considered to tolerate warnings much
better than most.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21185; Package emacs. (Thu, 06 Aug 2015 07:17:01 GMT) Full text and rfc822 format available.

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

From: Stephen Leake <stephen_leake <at> stephe-leake.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 21185 <at> debbugs.gnu.org
Subject: Re: bug#21185: 25.0.50; byte-compiler warn on quote lexical var
Date: Thu, 06 Aug 2015 02:15:42 -0500
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> I've been bitten by this problem when converting code to use lexical
>> binding; it would be helpful if the byte-compiler warned about it.
>
> Agreed, but I haven't figured out how to make this work.
> There are two problems:
> 1- detect not just things like « 'var » but also things like « '(var1
>    var2 var3) » since such occur in a few places as well.
> 2- don't swamp the user with false positives.
>
> Problem 2 is by far the biggest.  It's very common to have a local
> variable `face' and at the same time to use the symbol `face' (quoted),
> for example.
>
> I do have such a warning in my local hacks (it outputs a warning for any
> '<var> where <var> is a locally bound lexical variable) and find it
> unbearable, even though I'm usually considered to tolerate warnings much
> better than most.

Ok. Can you post your local hack? That would at least be useful during a
transition to lexical-binding: t; after that, testing should suffice.

-- 
-- Stephe




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21185; Package emacs. (Thu, 08 Jul 2021 14:14:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: stephen_leake <at> stephe-leake.org, 21185 <at> debbugs.gnu.org
Subject: Re: bug#21185: 25.0.50; byte-compiler warn on quote lexical var
Date: Thu, 08 Jul 2021 16:12:47 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> I've been bitten by this problem when converting code to use lexical
>> binding; it would be helpful if the byte-compiler warned about it.
>
> Agreed, but I haven't figured out how to make this work.
> There are two problems:
> 1- detect not just things like « 'var » but also things like « '(var1
>    var2 var3) » since such occur in a few places as well.
> 2- don't swamp the user with false positives.
>
> Problem 2 is by far the biggest.  It's very common to have a local
> variable `face' and at the same time to use the symbol `face' (quoted),
> for example.

So the suggestion is to have code like

(let ((foo "bar"))
  (when (zot 'foo)
     ...))

give a warning (in lexical code)?  That does sound useful, especially if
the `zot' here is `bound-and-true-p', which somebody was using in a
different bug report the other week.

But I think that Stefan is totally correct in 2) -- there will be so
many false positives that it won't be useful.  So I'm closing this bug
report.

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




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 08 Jul 2021 14:14:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 21185 <at> debbugs.gnu.org and stephen_leake <at> stephe-leake.org Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 08 Jul 2021 14:14:02 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. (Fri, 06 Aug 2021 11:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 255 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.