emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ace6eba: Fix byte-compiler warning for failed uses of lexical var


From: Stefan Kangas
Subject: master ace6eba: Fix byte-compiler warning for failed uses of lexical vars
Date: Tue, 1 Dec 2020 07:36:26 -0500 (EST)

branch: master
commit ace6eba036e64ff9eee6965951c48d0634b9c696
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    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.
---
 lisp/emacs-lisp/bytecomp.el                        |  2 +-
 .../error-lexical-var-with-add-hook.el             |  4 ++++
 .../error-lexical-var-with-remove-hook.el          |  4 ++++
 ...al-var-with-run-hook-with-args-until-failure.el |  3 +++
 ...al-var-with-run-hook-with-args-until-success.el |  3 +++
 .../error-lexical-var-with-run-hook-with-args.el   |  3 +++
 .../error-lexical-var-with-symbol-value.el         |  4 ++++
 test/lisp/emacs-lisp/bytecomp-tests.el             | 26 +++++++++++++++++++---
 8 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index a20f363..879f08a 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."
                              run-hook-with-args-until-failure))
           (pcase (cdr form)
             (`(',var . ,_)
-             (when (assq var byte-compile-lexical-variables)
+             (when (memq var byte-compile-lexical-variables)
                (byte-compile-report-error
                 (format-message "%s cannot use lexical var `%s'" fn var))))))
         ;; 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 0000000..5f39089
--- /dev/null
+++ b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-add-hook.el
@@ -0,0 +1,4 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (add-hook 'foo #'next-line)
+  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 0000000..eaa625e
--- /dev/null
+++ 
b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-remove-hook.el
@@ -0,0 +1,4 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (remove-hook 'foo #'next-line)
+  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 0000000..7a116ad
--- /dev/null
+++ 
b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-failure.el
@@ -0,0 +1,3 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (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 0000000..96d10a3
--- /dev/null
+++ 
b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args-until-success.el
@@ -0,0 +1,3 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (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 0000000..bb9101b
--- /dev/null
+++ 
b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-run-hook-with-args.el
@@ -0,0 +1,3 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (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 0000000..5f39089
--- /dev/null
+++ 
b/test/lisp/emacs-lisp/bytecomp-resources/error-lexical-var-with-symbol-value.el
@@ -0,0 +1,4 @@
+;;; -*- lexical-binding: t; -*-
+(let ((foo nil))
+  (add-hook 'foo #'next-line)
+  foo)
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el 
b/test/lisp/emacs-lisp/bytecomp-tests.el
index bea9663..d9052da 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."
   (should (equal (funcall 'def) -1)))
 
 (defmacro bytecomp--define-warning-file-test (file re-warning &optional 
reverse)
-  `(ert-deftest ,(intern (format "bytecomp-warn/%s" file)) ()
+  `(ert-deftest ,(intern (format "bytecomp/%s" file)) ()
      :expected-result ,(if reverse :failed :passed)
      (with-current-buffer (get-buffer-create "*Compile-Log*")
        (let ((inhibit-read-only t)) (erase-buffer))
@@ -556,9 +556,29 @@ Subtests signal errors if something goes wrong."
        (ert-info ((buffer-string) :prefix "buffer: ")
          (should (re-search-forward ,re-warning))))))
 
-(bytecomp--define-warning-file-test "warn-free-setq.el" "free.*foo")
+(bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el"
+                            "add-hook.*lexical var")
 
-(bytecomp--define-warning-file-test "warn-free-variable-reference.el" 
"free.*bar")
+(bytecomp--define-warning-file-test "error-lexical-var-with-remove-hook.el"
+                            "remove-hook.*lexical var")
+
+(bytecomp--define-warning-file-test 
"error-lexical-var-with-run-hook-with-args-until-failure.el"
+                            "args-until-failure.*lexical var")
+
+(bytecomp--define-warning-file-test 
"error-lexical-var-with-run-hook-with-args-until-success.el"
+                            "args-until-success.*lexical var")
+
+(bytecomp--define-warning-file-test 
"error-lexical-var-with-run-hook-with-args.el"
+                            "args.*lexical var")
+
+(bytecomp--define-warning-file-test "error-lexical-var-with-symbol-value.el"
+                            "symbol-value.*lexical var")
+
+(bytecomp--define-warning-file-test "warn-free-setq.el"
+                            "free.*foo")
+
+(bytecomp--define-warning-file-test "warn-free-variable-reference.el"
+                            "free.*bar")
 
 (bytecomp--define-warning-file-test "warn-obsolete-defun.el"
                             "foo-obsolete.*obsolete function.*99.99")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]