Subject: Re: bug#64232: 28.2; Incorrect(?) byte compilation warning about‘ansi-color-apply-on-region’

From: Michael Heerdegen <[email-masked]>
Date: Thu, 29 Jun 2023 05:43:13 +0200

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> > --- a/lisp/emacs-lisp/bytecomp.el
> > +++ b/lisp/emacs-lisp/bytecomp.el
> > @@ -554,7 +554,9 @@ byte-compile-initial-macro-environment
> >                                   (let ((byte-compile-unresolved-functions
> >                                          byte-compile-unresolved-functions)
> >                                         (byte-compile-new-defuns
> > -                                        byte-compile-new-defuns))
> > +                                        byte-compile-new-defuns)
> > +                                       (byte-compile-noruntime-functions
> > +                                        byte-compile-noruntime-functions))
> >                                     (setf result
> >                                           (byte-compile-eval
> >                                            (byte-run-strip-symbol-positions
>
> Hmm... this doesn't look right: one of the main purpose of
> `byte-compile-eval` is (beside calling `eval`) to populate
> `byte-compile-noruntime-functions`, so if you let-bind it around the
> call, it's like calling `eval` and we can just get rid of
> `byte-compile-noruntime-functions` altogether.

Hmm - ok.

> The "natural" place to put the let-binding would be in
> `byte-compile-close-variables` (assuming it still fixes the bug).

Seems it does not.  Maybe we should try to understand what is happening
first.

Part of the problem is the dependency

  check-declare -> compile -> comint -> ansi-color

so the compiler might think we are `requiring' ansi-color (which the
compiled file uses) inside our `eval-when-compile' by purpose.

The warning is the same as when one did just

#+begin_src emacs-lisp
(eval-when-compile
  (require 'ansi-color))
#+end_src

When removing that `eval-when-compile' the warning message goes away.
So the compiler warns stricter when something is required inside
`eval-when-compile', even if there would be no warning at all without
it.

Michael.