Subject: Re: bug#69120: Spurious "function is not known to be defined" if defined in `use-package` body

From: Konstantin Kharlamov <[email-masked]>
Date: Thu, 15 Feb 2024 07:00:40 +0300

On Thu, 2024-02-15 at 06:57 +0300, Konstantin Kharlamov wrote:
> On Wed, 2024-02-14 at 19:58 +0300, Konstantin Kharlamov wrote:
> > Mhm… Well, that does reduce the testcase to this code:
> > 
> >     ;;; -*- lexical-binding: t -*-
> >     (progn
> >       (defun hello()
> >         (print "hello"))
> >       (hello))
> > 
> > So the function is defined in the same visibility scope as where
> > it's
> > used, right
> > before its use, but byte-compiler apparently doesn't see that.
> 
> Turns out this false-positive is even more common than I thought.
> 
> As upstream Emacs deprecated `defadvice`, I'm porting `lsp-mode`
> plugin
> to an `advice-add`. They use it as a debugging facility, and there's
> an
> "advicing" call inside a `(defun …)`, and the function is defined
> inside the same `(defun …)` as well. And it also triggers the same
> warning. In terms of minimal testcase:
> 
>    ;;; -*- lexical-binding: t -*-
>    (defun foo ()
>      (defun hello()
>        (print "hello"))
>      (hello))

An interesting fact: inserting a `(declare-function hello nil)` after a
`defun` suppresses the warning. So I guess `defun` should work somehow
similarly to `declare-function`.