summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2010-09-15 17:30:43 +0200
committerStefan Monnier <monnier@iro.umontreal.ca>2010-09-15 17:30:43 +0200
commit4f1e996048a90f1177a98e7856b3250f04399e83 (patch)
tree441c8dccb89f30a25895ac215db258622df0d13e /lisp/emacs-lisp
parent01e80360d0b8390327ac30bbb37230970a7c1ddc (diff)
downloademacs-4f1e996048a90f1177a98e7856b3250f04399e83.tar.gz
emacs-4f1e996048a90f1177a98e7856b3250f04399e83.tar.bz2
emacs-4f1e996048a90f1177a98e7856b3250f04399e83.zip
* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-types): New type
`lexical' for warnings related to lexical scoping. (byte-compile-file-form-defvar, byte-compile-defvar): Warn about global vars which don't have a prefix and could hence affect lexical scoping in unrelated files.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/bytecomp.el12
1 files changed, 11 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 8b47e0421e0..cf12847d093 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -265,7 +265,7 @@ If it is 'byte, then only byte-level optimizations will be logged."
(defconst byte-compile-warning-types
'(redefine callargs free-vars unresolved
obsolete noruntime cl-functions interactive-only
- make-local mapcar constants suspicious)
+ make-local mapcar constants suspicious lexical)
"The list of warning types used when `byte-compile-warnings' is t.")
(defcustom byte-compile-warnings t
"List of warnings that the byte-compiler should issue (t for all).
@@ -2153,6 +2153,11 @@ list that represents a doc string reference.
;; Since there is no doc string, we can compile this as a normal form,
;; and not do a file-boundary.
(byte-compile-keep-pending form)
+ (when (and (symbolp (nth 1 form))
+ (not (string-match "[-*:$]" (symbol-name (nth 1 form))))
+ (byte-compile-warning-enabled-p 'lexical))
+ (byte-compile-warn "Global/dynamic var `%s' lacks a prefix"
+ (nth 1 form)))
(push (nth 1 form) byte-compile-bound-variables)
(if (eq (car form) 'defconst)
(push (nth 1 form) byte-compile-const-variables))
@@ -3804,6 +3809,11 @@ that suppresses all warnings during execution of BODY."
(defun byte-compile-defvar (form)
;; This is not used for file-level defvar/consts with doc strings.
+ (when (and (symbolp (nth 1 form))
+ (not (string-match "[-*:$]" (symbol-name (nth 1 form))))
+ (byte-compile-warning-enabled-p 'lexical))
+ (byte-compile-warn "Global/dynamic var `%s' lacks a prefix"
+ (nth 1 form)))
(let ((fun (nth 0 form))
(var (nth 1 form))
(value (nth 2 form))