From 82875b15750401daa358c1bebaba5969b96f0d88 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 27 Jun 2023 16:14:32 -0400 Subject: [PATCH] cl-macs-tests.el (cl-&key-arguments): Fix regression * lisp/emacs-lisp/bytecomp.el (byte-compile-form): Turn "cannot use lexical var" errors into warnings. Make the obey `with-suppressed-warnings`. * test/lisp/emacs-lisp/cl-macs-tests.el (cl-&key-arguments): Suppress warnings. --- lisp/emacs-lisp/bytecomp.el | 5 +++-- test/lisp/emacs-lisp/cl-macs-tests.el | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 659d698b603..99202185d8d 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3473,8 +3473,9 @@ lambda-expression." run-hook-with-args-until-failure)) (pcase (cdr form) (`(',var . ,_) - (when (memq var byte-compile-lexical-variables) - (byte-compile-report-error + (when (and (memq var byte-compile-lexical-variables) + (byte-compile-warning-enabled-p 'lexical var)) + (byte-compile-warn (format-message "%s cannot use lexical var `%s'" fn var)))))) ;; Warn about using obsolete hooks. (if (memq fn '(add-hook remove-hook)) diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el index 01ca56386e3..983cbfc8bc7 100644 --- a/test/lisp/emacs-lisp/cl-macs-tests.el +++ b/test/lisp/emacs-lisp/cl-macs-tests.el @@ -812,8 +812,10 @@ See Bug#57915." ;; In ELisp function arguments are always statically scoped (bug#47552). (let ((cl--test-a 'dyn) ;; FIXME: How do we silence the "Lexical argument shadows" warning? - (f (cl-function (lambda (&key cl--test-a b) - (list cl--test-a (symbol-value 'cl--test-a) b))))) + (f + (with-suppressed-warnings ((lexical cl--test-a)) + (cl-function (lambda (&key cl--test-a b) + (list cl--test-a (symbol-value 'cl--test-a) b)))))) (should (equal (funcall f :cl--test-a 'lex :b 2) '(lex dyn 2))))) (cl-defstruct cl--test-s -- 2.39.2