* byte-compiler warn on quote lexical var?
@ 2015-08-04 14:01 Stephen Leake
2015-08-08 13:57 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Leake @ 2015-08-04 14:01 UTC (permalink / raw)
To: emacs-devel
I've posted bug#21185; it suggests that the byte-compiler should warn
when a lexical variable is quoted.
For example, with this code:
;; -*- 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)))
the call to 'display-var' reports "not bound".
I've been bitten by this problem a couple of times when porting code to
lexical binding; I'd like the byte-compiler to warn me about it.
Is that reasonable?
Can anyone point me to where in the byte-compiler code I should look to
start working on adding this?
--
-- Stephe
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: byte-compiler warn on quote lexical var?
2015-08-04 14:01 byte-compiler warn on quote lexical var? Stephen Leake
@ 2015-08-08 13:57 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2015-08-08 13:57 UTC (permalink / raw)
To: Stephen Leake; +Cc: emacs-devel
> Can anyone point me to where in the byte-compiler code I should look to
> start working on adding this?
I think the patch below is what I used.
Stefan
diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el
index 98eef11..df2865f 100644
--- a/lisp/emacs-lisp/cconv.el
+++ b/lisp/emacs-lisp/cconv.el
@@ -664,6 +675,10 @@
(`(cond . ,cond-forms) ; cond special form
(dolist (forms cond-forms)
(dolist (form forms) (cconv-analyze-form form env))))
+
+ ;; ((and `(quote ,v . ,_) (guard (assq v env)))
+ ;; (byte-compile-log-warning
+ ;; (format "Possible confusion variable/symbol for `%S'" v)))
(`(quote . ,_) nil) ; quote form
(`(function . ,_) nil) ; same as quote
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-08-08 13:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-04 14:01 byte-compiler warn on quote lexical var? Stephen Leake
2015-08-08 13:57 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).