(byte-compile-const-symbol-p):
Recognize immutable variables like most-positive-fixnum. (byte-compile-setq-default): Check and warn if trying to assign to an immutable variable, or a non-variable.
This commit is contained in:
parent
76a87a4d3c
commit
d988dbf687
2 changed files with 22 additions and 4 deletions
|
@ -1,5 +1,10 @@
|
||||||
2009-08-29 Stefan Monnier <monnier@iro.umontreal.ca>
|
2009-08-29 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||||
|
|
||||||
|
* emacs-lisp/bytecomp.el (byte-compile-const-symbol-p):
|
||||||
|
Recognize immutable variables like most-positive-fixnum.
|
||||||
|
(byte-compile-setq-default): Check and warn if trying to assign
|
||||||
|
to an immutable variable, or a non-variable.
|
||||||
|
|
||||||
* progmodes/cc-vars.el (c-comment-continuation-stars):
|
* progmodes/cc-vars.el (c-comment-continuation-stars):
|
||||||
* progmodes/cc-engine.el (c-looking-at-bos):
|
* progmodes/cc-engine.el (c-looking-at-bos):
|
||||||
* progmodes/cc-cmds.el (c-toggle-auto-state)
|
* progmodes/cc-cmds.el (c-toggle-auto-state)
|
||||||
|
|
|
@ -1506,7 +1506,14 @@ If ANY-VALUE is nil, only return non-nil if the value of the symbol is the
|
||||||
symbol itself."
|
symbol itself."
|
||||||
(or (memq symbol '(nil t))
|
(or (memq symbol '(nil t))
|
||||||
(keywordp symbol)
|
(keywordp symbol)
|
||||||
(if any-value (memq symbol byte-compile-const-variables))))
|
(if any-value
|
||||||
|
(or (memq symbol byte-compile-const-variables)
|
||||||
|
;; FIXME: We should provide a less intrusive way to find out
|
||||||
|
;; is a variable is "constant".
|
||||||
|
(and (boundp symbol)
|
||||||
|
(condition-case nil
|
||||||
|
(progn (set symbol (symbol-value symbol)) nil)
|
||||||
|
(setting-constant t)))))))
|
||||||
|
|
||||||
(defmacro byte-compile-constp (form)
|
(defmacro byte-compile-constp (form)
|
||||||
"Return non-nil if FORM is a constant."
|
"Return non-nil if FORM is a constant."
|
||||||
|
@ -3483,9 +3490,15 @@ That command is designed for interactive use only" fn))
|
||||||
(let ((args (cdr form))
|
(let ((args (cdr form))
|
||||||
setters)
|
setters)
|
||||||
(while args
|
(while args
|
||||||
(setq setters
|
(let ((var (car args)))
|
||||||
(cons (list 'set-default (list 'quote (car args)) (car (cdr args)))
|
(if (or (not (symbolp var))
|
||||||
setters))
|
(byte-compile-const-symbol-p var t))
|
||||||
|
(byte-compile-warn
|
||||||
|
"variable assignment to %s `%s'"
|
||||||
|
(if (symbolp var) "constant" "nonvariable")
|
||||||
|
(prin1-to-string var)))
|
||||||
|
(push (list 'set-default (list 'quote var) (car (cdr args)))
|
||||||
|
setters))
|
||||||
(setq args (cdr (cdr args))))
|
(setq args (cdr (cdr args))))
|
||||||
(byte-compile-form (cons 'progn (nreverse setters)))))
|
(byte-compile-form (cons 'progn (nreverse setters)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue