Subject: Re: bug#39823: 26.3; update-directory-autoloads regression from Emacs 26 to Emacs 27

From: Maxim Cournoyer <[email-masked]>
Date: Fri, 13 Mar 2020 22:03:36 -0400

Hello!

Noam Postavsky <[email-masked]> writes:

> Maxim Cournoyer <[email-masked]> writes:
>
>> After passing from Emacs 26 to Emacs 27, the following snippet of code
>> doesn't behave the same:
>>
>> emacs --quick --batch --eval "(progn
>>  ;(require 'autoload)
>>  (let ((backup-inhibited t)
>>        (generated-autoload-file \"/tmp/toto\"))
>>    (update-directory-autoloads \"/tmp\")))"
>>
>>
>> Works on Emacs 26.3, but fails on Emacs 27.0.50, with the error message:
>>
>> Wrong type argument: stringp, nil
>
> The difference is that --eval now evaluates with lexical-binding
> enabled, so the let-binding of generated-autoload-file is lexical unless
> autoload.el, with its (defvar generated-autoload-file nil ...), has been
> loaded.  Another way to demonstrate this:
>
>     emacs -Q --batch -l bug-39823-autoload-regression.el
>
> fails with the same error, with bug-39823-autoload-regression.el as the
> attached file in both Emacs 26 and 27.  Remove the lexical-binding
> setting, and it succeeds in both.

Thank you for opening my eyes on this; I was scratching my head a bit.

> See also https://lists.gnu.org/r/emacs-devel/2020-03/msg00173.html for
> (much) more discussion on this.

Eh, indeed, that was a bit much :-).  I have nothing against lexcal
scoping (all to the contrary), and always found it strange that I had to
dynamically bound values variable calling `update-directory-autoloads'.
Perhaps a simple fix would be to allow passing the values it needs as
arguments (while maintaining backward compatibility, i.e., make those
arguments optional?).

Maxim