Subject: bug#26837: Wrong file in "autoloading failed to define" error

From: Glenn Morris <[email-masked]>
Date: Sat, 20 May 2017 19:17:30 -0400

Alex wrote:

> That seems to work for me as well. Should it be documented that
> reevaluations of a file update the position of the file in load-history?

I think it's mentioned in the doc of load:

  Loading a file records its definitions, and its `provide' and
  `require' calls, in an element of `load-history' whose
  car is the file name loaded.  See `load-history'.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
but that did seem to be the only mention I found in a quick search.

> PS: I realized that I was a bit careless in using SDATA without checking
> that the argument is necessarily a string. I don't think it matters much
> if your above patch is applied, but it's probably not a good idea to
> leave it in, just in case there's a bug somewhere else in the future.

In 58326f0 I check if the car is nil (though I don't see how it could be).
Could add the same thing to eval.c.

> What do you think about the following diff? This removes the dependency
> on load-history altogether:
>
> --- a/src/eval.c
> +++ b/src/eval.c
> @@ -2021,7 +2021,10 @@ it defines a macro.  */)
>  
>        if (!NILP (Fequal (fun, fundef)))
>         error ("Autoloading file %s failed to define function %s",
> -              SDATA (Fcar (Fcar (Vload_history))),
> +              SDATA (Flocate_file_internal (Fcar (Fcdr (fundef)),
> +                                            Vload_path,
> +                                            Vload_suffixes,
> +                                            Qnil)),
>                SDATA (SYMBOL_NAME (funname)));
>        else
>         return fun;

I don't have an informed opinion right now.