diff options
| author | Mattias EngdegÄrd | 2022-09-22 14:15:56 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2022-09-22 14:54:15 +0200 |
| commit | e4964de952a8246307faaf9875d2c278f42c53fc (patch) | |
| tree | abed0eca68ab4e72954e39d52bb791491d80519d /test | |
| parent | e9f42b1cba08c3a20db86d8a98f7e9cfe22569d7 (diff) | |
| download | emacs-e4964de952a8246307faaf9875d2c278f42c53fc.tar.gz emacs-e4964de952a8246307faaf9875d2c278f42c53fc.zip | |
Don't rewrite `set` to `setq` of lexical variables
Only perform the rewrite
(set 'VAR X) -> (setq VAR X)
for dynamic variables, as `set` isn't supposed to affect
lexical vars (and never does so when interpreted).
* lisp/emacs-lisp/byte-opt.el (byte-optimize-set):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--xx): New.
(bytecomp-tests--test-cases): Add test cases.
* test/lisp/emacs-lisp/bytecomp-resources/warn-variable-set-nonvariable.el:
Remove obsolete test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-resources/warn-variable-set-nonvariable.el | 3 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 15 |
2 files changed, 12 insertions, 6 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/warn-variable-set-nonvariable.el b/test/lisp/emacs-lisp/bytecomp-resources/warn-variable-set-nonvariable.el deleted file mode 100644 index 0c76c4d388b..00000000000 --- a/test/lisp/emacs-lisp/bytecomp-resources/warn-variable-set-nonvariable.el +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | ;;; -*- lexical-binding: t -*- | ||
| 2 | (defun foo () | ||
| 3 | (set '(a) nil)) | ||
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 1ca44dc7a48..e7c308213e4 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -59,6 +59,8 @@ inner loops respectively." | |||
| 59 | (setq i (1- i))) | 59 | (setq i (1- i))) |
| 60 | res)) | 60 | res)) |
| 61 | 61 | ||
| 62 | (defvar bytecomp-tests--xx nil) | ||
| 63 | |||
| 62 | (defconst bytecomp-tests--test-cases | 64 | (defconst bytecomp-tests--test-cases |
| 63 | '( | 65 | '( |
| 64 | ;; some functional tests | 66 | ;; some functional tests |
| @@ -692,6 +694,16 @@ inner loops respectively." | |||
| 692 | (f (lambda () | 694 | (f (lambda () |
| 693 | (let ((y x)) (list y 3 y))))) | 695 | (let ((y x)) (list y 3 y))))) |
| 694 | (funcall f)) | 696 | (funcall f)) |
| 697 | |||
| 698 | ;; Test rewriting of `set' to `setq' (only done on dynamic variables). | ||
| 699 | (let ((xx 1)) (set 'xx 2) xx) | ||
| 700 | (let ((bytecomp-tests--xx 1)) | ||
| 701 | (set 'bytecomp-tests--xx 2) | ||
| 702 | bytecomp-tests--xx) | ||
| 703 | (let ((aaa 1)) (set (make-local-variable 'aaa) 2) aaa) | ||
| 704 | (let ((bytecomp-tests--xx 1)) | ||
| 705 | (set (make-local-variable 'bytecomp-tests--xx) 2) | ||
| 706 | bytecomp-tests--xx) | ||
| 695 | ) | 707 | ) |
| 696 | "List of expressions for cross-testing interpreted and compiled code.") | 708 | "List of expressions for cross-testing interpreted and compiled code.") |
| 697 | 709 | ||
| @@ -953,9 +965,6 @@ byte-compiled. Run with dynamic binding." | |||
| 953 | (bytecomp--define-warning-file-test "warn-variable-set-constant.el" | 965 | (bytecomp--define-warning-file-test "warn-variable-set-constant.el" |
| 954 | "attempt to set constant") | 966 | "attempt to set constant") |
| 955 | 967 | ||
| 956 | (bytecomp--define-warning-file-test "warn-variable-set-nonvariable.el" | ||
| 957 | "variable reference to nonvariable") | ||
| 958 | |||
| 959 | (bytecomp--define-warning-file-test "warn-variable-setq-nonvariable.el" | 968 | (bytecomp--define-warning-file-test "warn-variable-setq-nonvariable.el" |
| 960 | "attempt to set non-variable") | 969 | "attempt to set non-variable") |
| 961 | 970 | ||