GNU bug report logs - #64232
28.2; Incorrect(?) byte compilation warning about ‘ansi-color-apply-on-region’

Previous Next

Package: emacs;

Reported by: Zack Weinberg <zack <at> owlfolio.org>

Date: Thu, 22 Jun 2023 19:57:02 UTC

Severity: normal

Found in version 28.2

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Zack Weinberg <zack <at> owlfolio.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 64232 <at> debbugs.gnu.org
Subject: bug#64232: 28.2; Incorrect(?) byte compilation warning about ‘ansi-color-apply-on-region’
Date: Sat, 24 Jun 2023 14:49:43 +0300
> Date: Thu, 22 Jun 2023 15:56:18 -0400
> From: Zack Weinberg <zack <at> owlfolio.org>
> 
> 
> With Emacs 28.2, this test .el file
> 
> ```
> ;; -*- lexical-binding: t; coding: utf-8 -*-
> 
> (declare-function ansi-color-apply-on-region "ansi-color"
>                   (begin end &optional preserve-sequences))
> (autoload 'ansi-color-apply-on-region "ansi-color")
> 
> (eval-when-compile
>   (check-declare-file byte-compile-current-file))
> 
> (defun zw-colorize-compilation-buffer ()
>   "Interpret ANSI color escapes in a compilation-mode buffer, which
> gets them out of the way of the error detector.  Intended for use via
> compilation-filter-hook."
>   (interactive)
>   (let ((inhibit-read-only t))
>     (ansi-color-apply-on-region (point-min) (point-max))))
> ```
> 
> provokes a byte compilation warning:
> 
> ```
> $ emacs -Q --batch -f batch-byte-compile test.el
> uncompressing ansi-color.el.gz...
> uncompressing ansi-color.el.gz...done
> 
> In end of data:
> test.el:16:6: Warning: the function ‘ansi-color-apply-on-region’ might not be
>     defined at runtime.
> ```
> 
> The combination of `declare-function` and `autoload` is intended to
> ensure both that the byte compiler understands what’s going on, and
> that `ansi-color-apply-on-region` really is guaranteed to be available
> at runtime.  Also, I triple-checked that ansi-color.el really does
> define this function.  Why is the compiler still complaining?

The problem is this part:

  (eval-when-compile
    (check-declare-file byte-compile-current-file))

Remove it, and the problem will go away.  So there's actually no
problem here with 'autoload' and 'declare-function'.

I don't understand why you are calling check-declare-file, and
moreover don't understand the argument you pass check-declare-file.
check-declare-file is a command supposed to be used interactively to
verify the 'declare' calls are valid in a given file; it shows the
results, if any, as delayed-warnings.  Can you explain why you do this
in the eval-when-compile form?




This bug report was last modified 1 year and 323 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.