diff options
| author | Stefan Monnier | 2009-08-29 14:44:45 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-08-29 14:44:45 +0000 |
| commit | d988dbf687f64c173f8dea5dec13886b04ffda6c (patch) | |
| tree | e0eaa96dfb280d8b687935cc09fc2ea58480a5b1 | |
| parent | 76a87a4d3ca9884afc5cb663990deccdf72ef6f3 (diff) | |
| download | emacs-d988dbf687f64c173f8dea5dec13886b04ffda6c.tar.gz emacs-d988dbf687f64c173f8dea5dec13886b04ffda6c.zip | |
(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.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 21 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 50869b07c95..528538545de 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2009-08-29 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2009-08-29 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * emacs-lisp/bytecomp.el (byte-compile-const-symbol-p): | ||
| 4 | Recognize immutable variables like most-positive-fixnum. | ||
| 5 | (byte-compile-setq-default): Check and warn if trying to assign | ||
| 6 | to an immutable variable, or a non-variable. | ||
| 7 | |||
| 3 | * progmodes/cc-vars.el (c-comment-continuation-stars): | 8 | * progmodes/cc-vars.el (c-comment-continuation-stars): |
| 4 | * progmodes/cc-engine.el (c-looking-at-bos): | 9 | * progmodes/cc-engine.el (c-looking-at-bos): |
| 5 | * progmodes/cc-cmds.el (c-toggle-auto-state) | 10 | * progmodes/cc-cmds.el (c-toggle-auto-state) |
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index c234fd70a43..1aa63e3bec0 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -1506,7 +1506,14 @@ If ANY-VALUE is nil, only return non-nil if the value of the symbol is the | |||
| 1506 | symbol itself." | 1506 | symbol itself." |
| 1507 | (or (memq symbol '(nil t)) | 1507 | (or (memq symbol '(nil t)) |
| 1508 | (keywordp symbol) | 1508 | (keywordp symbol) |
| 1509 | (if any-value (memq symbol byte-compile-const-variables)))) | 1509 | (if any-value |
| 1510 | (or (memq symbol byte-compile-const-variables) | ||
| 1511 | ;; FIXME: We should provide a less intrusive way to find out | ||
| 1512 | ;; is a variable is "constant". | ||
| 1513 | (and (boundp symbol) | ||
| 1514 | (condition-case nil | ||
| 1515 | (progn (set symbol (symbol-value symbol)) nil) | ||
| 1516 | (setting-constant t))))))) | ||
| 1510 | 1517 | ||
| 1511 | (defmacro byte-compile-constp (form) | 1518 | (defmacro byte-compile-constp (form) |
| 1512 | "Return non-nil if FORM is a constant." | 1519 | "Return non-nil if FORM is a constant." |
| @@ -3483,9 +3490,15 @@ That command is designed for interactive use only" fn)) | |||
| 3483 | (let ((args (cdr form)) | 3490 | (let ((args (cdr form)) |
| 3484 | setters) | 3491 | setters) |
| 3485 | (while args | 3492 | (while args |
| 3486 | (setq setters | 3493 | (let ((var (car args))) |
| 3487 | (cons (list 'set-default (list 'quote (car args)) (car (cdr args))) | 3494 | (if (or (not (symbolp var)) |
| 3488 | setters)) | 3495 | (byte-compile-const-symbol-p var t)) |
| 3496 | (byte-compile-warn | ||
| 3497 | "variable assignment to %s `%s'" | ||
| 3498 | (if (symbolp var) "constant" "nonvariable") | ||
| 3499 | (prin1-to-string var))) | ||
| 3500 | (push (list 'set-default (list 'quote var) (car (cdr args))) | ||
| 3501 | setters)) | ||
| 3489 | (setq args (cdr (cdr args)))) | 3502 | (setq args (cdr (cdr args)))) |
| 3490 | (byte-compile-form (cons 'progn (nreverse setters))))) | 3503 | (byte-compile-form (cons 'progn (nreverse setters))))) |
| 3491 | 3504 | ||