Mercurial > emacs
comparison lisp/emacs-lisp/bytecomp.el @ 108085:34eca4ecfbe6
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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 23 Apr 2010 12:26:11 -0400 |
parents | 1d1d5d9bd884 |
children | f3d817d46523 |
comparison
equal
deleted
inserted
replaced
108084:7ffbe3a6a8f2 | 108085:34eca4ecfbe6 |
---|---|
3331 ;; (setq), with no arguments. | 3331 ;; (setq), with no arguments. |
3332 (byte-compile-form nil for-effect)) | 3332 (byte-compile-form nil for-effect)) |
3333 (setq for-effect nil))) | 3333 (setq for-effect nil))) |
3334 | 3334 |
3335 (defun byte-compile-setq-default (form) | 3335 (defun byte-compile-setq-default (form) |
3336 (let ((bytecomp-args (cdr form)) | 3336 (setq form (cdr form)) |
3337 setters) | 3337 (if (> (length form) 2) |
3338 (while bytecomp-args | 3338 (let ((setters ())) |
3339 (let ((var (car bytecomp-args))) | 3339 (while (consp form) |
3340 (and (or (not (symbolp var)) | 3340 (push `(setq-default ,(pop form) ,(pop form)) setters)) |
3341 (byte-compile-const-symbol-p var t)) | 3341 (byte-compile-form (cons 'progn (nreverse setters)))) |
3342 (byte-compile-warning-enabled-p 'constants) | 3342 (let ((var (car form))) |
3343 (byte-compile-warn | 3343 (and (or (not (symbolp var)) |
3344 "variable assignment to %s `%s'" | 3344 (byte-compile-const-symbol-p var t)) |
3345 (if (symbolp var) "constant" "nonvariable") | 3345 (byte-compile-warning-enabled-p 'constants) |
3346 (prin1-to-string var))) | 3346 (byte-compile-warn |
3347 (push (list 'set-default (list 'quote var) (car (cdr bytecomp-args))) | 3347 "variable assignment to %s `%s'" |
3348 setters)) | 3348 (if (symbolp var) "constant" "nonvariable") |
3349 (setq bytecomp-args (cdr (cdr bytecomp-args)))) | 3349 (prin1-to-string var))) |
3350 (byte-compile-form (cons 'progn (nreverse setters))))) | 3350 (byte-compile-normal-call `(set-default ',var ,@(cdr form)))))) |
3351 | |
3352 (byte-defop-compiler-1 set-default) | |
3353 (defun byte-compile-set-default (form) | |
3354 (let ((varexp (car-safe (cdr-safe form)))) | |
3355 (if (eq (car-safe varexp) 'quote) | |
3356 ;; If the varexp is constant, compile it as a setq-default | |
3357 ;; so we get more warnings. | |
3358 (byte-compile-setq-default `(setq-default ,(car-safe (cdr varexp)) | |
3359 ,@(cddr form))) | |
3360 (byte-compile-normal-call form)))) | |
3351 | 3361 |
3352 (defun byte-compile-quote (form) | 3362 (defun byte-compile-quote (form) |
3353 (byte-compile-constant (car (cdr form)))) | 3363 (byte-compile-constant (car (cdr form)))) |
3354 | 3364 |
3355 (defun byte-compile-quote-form (form) | 3365 (defun byte-compile-quote-form (form) |