Compiler invalid reporting warning. An Emacs 30 compiler limitation/bug?

Pierre Rouleau <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <CALTqLianH2K82LFJ1JO9wbi6B71zn1cHA6xwP6bsPQ6ADoqHYQ@mail.gmail.com>
Hi all,

Emacs 30.2.50 reports an unused lexical variable warning
for code where the variable is used inside a cl-letf macro.
Is this a limitation to the compiler that should be reported
to the development list?
Should this also be reported as an Emacs bug?

The code is test code for some of my stuff:

(ert-deftest ert-test-pel-elcode-print-properties-of-sexp-at-point--quote ()
  "PR regression: `quote' forms must not degrade purity in the printed
output."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun check-mode (mode) (eq mode 'text-mode))")
    (goto-char (point-min))
    (let ((kill-ring nil)
          (captured-message nil))  ; <<<--- WARNING: Unused lexical
variable ‘captured-message’
      (cl-letf (((symbol-function 'message)
                 (lambda (fmt &rest args)
                   (setq captured-message ; <<<---- but it's used here!
                         (apply #'format fmt args)))))
        (pel-elcode-print-properties-of-sexp-at-point))
      (should (equal (car kill-ring)
                     "(declare (pure t) (side-effect-free error-free))")))))

This is using Emacs 30.2.50 I built from source some in november 2025.

-- 
/Pierre
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.