aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2020-12-01 13:34:17 +0100
committerStefan Kangas2020-12-01 13:35:03 +0100
commitace6eba036e64ff9eee6965951c48d0634b9c696 (patch)
tree70a26905403b702a68330faa12bfa720ce1fdb8f
parent8a27b0cad7dcffd0af9b3b38028ac12276a85c1b (diff)
downloademacs-ace6eba036e64ff9eee6965951c48d0634b9c696.tar.gz
emacs-ace6eba036e64ff9eee6965951c48d0634b9c696.zip
Fix byte-compiler warning for failed uses of lexical vars
* lisp/emacs-lisp/bytecomp.el (byte-compile-form): Fix byte-compiler warning for failed uses of lexical vars. (Bug#44980) * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--define-warning-file-test): Don't prefix tests with 'warn'. (bytecomp/error-lexical-var-with-add-hook\.el) (bytecomp/error-lexical-var-with-remove-hook\.el) (bytecomp/error-lexical-var-with-run-hook-with-args-until-failure\.el) (bytecomp/error-lexical-var-with-run-hook-with-args-until-success\.el) (bytecomp/error-lexical-var-with-run-hook-with-args\.el) (bytecomp/error-lexical-var-with-symbol-value\.el): New tests. * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el: * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el: * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el: * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el: * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el: * test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el: New files.
-rw-r--r--lisp/emacs-lisp/bytecomp.el2
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el4
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el4
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el3
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el3
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el3
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el4
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el26
8 files changed, 45 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index a20f3634560..879f08a09f6 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3203,7 +3203,7 @@ for symbols generated by the byte compiler itself."
3203 run-hook-with-args-until-failure)) 3203 run-hook-with-args-until-failure))
3204 (pcase (cdr form) 3204 (pcase (cdr form)
3205 (`(',var . ,_) 3205 (`(',var . ,_)
3206 (when (assq var byte-compile-lexical-variables) 3206 (when (memq var byte-compile-lexical-variables)
3207 (byte-compile-report-error 3207 (byte-compile-report-error
3208 (format-message "%s cannot use lexical var `%s'" fn var)))))) 3208 (format-message "%s cannot use lexical var `%s'" fn var))))))
3209 ;; Warn about using obsolete hooks. 3209 ;; Warn about using obsolete hooks.
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el
new file mode 100644
index 00000000000..5f390898e6a
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el
@@ -0,0 +1,4 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (add-hook 'foo #'next-line)
4 foo)
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el
new file mode 100644
index 00000000000..eaa625eba1c
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el
@@ -0,0 +1,4 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (remove-hook 'foo #'next-line)
4 foo)
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el
new file mode 100644
index 00000000000..7a116ad464b
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el
@@ -0,0 +1,3 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (run-hook-with-args-until-failure 'foo))
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el
new file mode 100644
index 00000000000..96d10a343df
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el
@@ -0,0 +1,3 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (run-hook-with-args-until-success 'foo #'next-line))
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el
new file mode 100644
index 00000000000..bb9101bd070
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el
@@ -0,0 +1,3 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (run-hook-with-args 'foo))
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el
new file mode 100644
index 00000000000..5f390898e6a
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el
@@ -0,0 +1,4 @@
1;;; -*- lexical-binding: t; -*-
2(let ((foo nil))
3 (add-hook 'foo #'next-line)
4 foo)
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index bea9663d241..d9052da5436 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -548,7 +548,7 @@ Subtests signal errors if something goes wrong."
548 (should (equal (funcall 'def) -1))) 548 (should (equal (funcall 'def) -1)))
549 549
550(defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse) 550(defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse)
551 `(ert-deftest ,(intern (format "bytecomp-warn/%s" file)) () 551 `(ert-deftest ,(intern (format "bytecomp/%s" file)) ()
552 :expected-result ,(if reverse :failed :passed) 552 :expected-result ,(if reverse :failed :passed)
553 (with-current-buffer (get-buffer-create "*Compile-Log*") 553 (with-current-buffer (get-buffer-create "*Compile-Log*")
554 (let ((inhibit-read-only t)) (erase-buffer)) 554 (let ((inhibit-read-only t)) (erase-buffer))
@@ -556,9 +556,29 @@ Subtests signal errors if something goes wrong."
556 (ert-info ((buffer-string) :prefix "buffer: ") 556 (ert-info ((buffer-string) :prefix "buffer: ")
557 (should (re-search-forward ,re-warning)))))) 557 (should (re-search-forward ,re-warning))))))
558 558
559(bytecomp--define-warning-file-test "warn-free-setq.el" "free.*foo") 559(bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el"
560 "add-hook.*lexical var")
560 561
561(bytecomp--define-warning-file-test "warn-free-variable-reference.el" "free.*bar") 562(bytecomp--define-warning-file-test "error-lexical-var-with-remove-hook.el"
563 "remove-hook.*lexical var")
564
565(bytecomp--define-warning-file-test "error-lexical-var-with-run-hook-with-args-until-failure.el"
566 "args-until-failure.*lexical var")
567
568(bytecomp--define-warning-file-test "error-lexical-var-with-run-hook-with-args-until-success.el"
569 "args-until-success.*lexical var")
570
571(bytecomp--define-warning-file-test "error-lexical-var-with-run-hook-with-args.el"
572 "args.*lexical var")
573
574(bytecomp--define-warning-file-test "error-lexical-var-with-symbol-value.el"
575 "symbol-value.*lexical var")
576
577(bytecomp--define-warning-file-test "warn-free-setq.el"
578 "free.*foo")
579
580(bytecomp--define-warning-file-test "warn-free-variable-reference.el"
581 "free.*bar")
562 582
563(bytecomp--define-warning-file-test "warn-obsolete-defun.el" 583(bytecomp--define-warning-file-test "warn-obsolete-defun.el"
564 "foo-obsolete.*obsolete function.*99.99") 584 "foo-obsolete.*obsolete function.*99.99")