diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2010-04-23 12:26:11 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2010-04-23 12:26:11 -0400 |
commit | 9ae0c31028f246f77a16f4989d5c63bfbbee4832 (patch) | |
tree | 4eec67ea6b8cbfb6c3a9f7eef29239608b09404c /lisp/emacs-lisp | |
parent | bd486b039f9478afaff25e358b9e2c615e39f5c6 (diff) | |
download | emacs-9ae0c31028f246f77a16f4989d5c63bfbbee4832.tar.gz emacs-9ae0c31028f246f77a16f4989d5c63bfbbee4832.tar.bz2 emacs-9ae0c31028f246f77a16f4989d5c63bfbbee4832.zip |
Provide byte-compiler warnings when set-default a read-only var.
* emacs-lisp/bytecomp.el (byte-compile-set-default): New function.
(byte-compile-setq-default): Optimize for the
single-var case and don't call byte-compile-form in this case to avoid
inf-loop with byte-compile-set-default.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index b593596a526..0c3a7b69798 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3333,21 +3333,31 @@ If it is nil, then the handler is \"byte-compile-SYMBOL.\"" (setq for-effect nil))) (defun byte-compile-setq-default (form) - (let ((bytecomp-args (cdr form)) - setters) - (while bytecomp-args - (let ((var (car bytecomp-args))) - (and (or (not (symbolp var)) - (byte-compile-const-symbol-p var t)) - (byte-compile-warning-enabled-p 'constants) - (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 bytecomp-args))) - setters)) - (setq bytecomp-args (cdr (cdr bytecomp-args)))) - (byte-compile-form (cons 'progn (nreverse setters))))) + (setq form (cdr form)) + (if (> (length form) 2) + (let ((setters ())) + (while (consp form) + (push `(setq-default ,(pop form) ,(pop form)) setters)) + (byte-compile-form (cons 'progn (nreverse setters)))) + (let ((var (car form))) + (and (or (not (symbolp var)) + (byte-compile-const-symbol-p var t)) + (byte-compile-warning-enabled-p 'constants) + (byte-compile-warn + "variable assignment to %s `%s'" + (if (symbolp var) "constant" "nonvariable") + (prin1-to-string var))) + (byte-compile-normal-call `(set-default ',var ,@(cdr form)))))) + +(byte-defop-compiler-1 set-default) +(defun byte-compile-set-default (form) + (let ((varexp (car-safe (cdr-safe form)))) + (if (eq (car-safe varexp) 'quote) + ;; If the varexp is constant, compile it as a setq-default + ;; so we get more warnings. + (byte-compile-setq-default `(setq-default ,(car-safe (cdr varexp)) + ,@(cddr form))) + (byte-compile-normal-call form)))) (defun byte-compile-quote (form) (byte-compile-constant (car (cdr form)))) |