Subject: bug#67025: 29.1; Error in Emacs 29.1 when installing seq from ELPA

From: Steve Purcell <[email-masked]>
Date: Thu, 9 Nov 2023 18:47:57 +0000

--text follows this line--

Passing on the following from a correspondent who didn't want to file a
bug themselves:

----------------------------------------------------------------------------
To reproduce, save the following Elisp snippet:

(require 'package)
(setf package-user-dir "/tmp/elpa"
      package-archives '(("gnu-devel" . "https://elpa.gnu.org/devel/")))
(package-refresh-contents)
(let ((debug-on-error t))
  (package-install (cadr (assq 'seq package-archive-contents))))

and then from the command line run:

$ emacs --batch --load bug.el

Result here:

$ emacs --batch --load ~/test/test.el
Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443
Contacting host: elpa.gnu.org:443
Package refresh done
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Contacting host: elpa.gnu.org:443
Parsing tar file... 
Parsing tar file...done
Extracting... \ 
Extracting...done
  INFO     Scraping files for loaddefs... 
  INFO     Scraping files for loaddefs...done
Source file ‘/tmp/elpa/seq-2.24.0.20230904.183335/seq.el’ newer than byte-compiled file; using older file
Debugger entered--Lisp error: (file-missing "Cannot open load file" "No such file or directory" "seq-25")
  require(seq-25)
  byte-code("\301\10\302\"\203\16\0\303\304!\210\202\22\0\303\305!\210\306\307!\207" [emacs-version version< "25" require seq-24 seq-25 provide seq] 3)
  #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_32>(("/tmp/elpa/seq-2.24.0.20230904.183335/seq" . 76))
  ...
----------------------------------------------------------------------------

My interpretation:

After installing the ELPA version of seq, Emacs decides it must re-load
seq (presumably because it was already loaded from the built-in
version), and then loads seq.el from the downloaded ELPA package. The
problem is that at this point it hasn't added the new ELPA package's
installation directory to load-path, so when seq.el tries to load
seq-25.el, Emacs fails to find that file.

In my own Emacs config, this led to first-time start-up errors in Emacs
29.1 (only), ie. when installing required packages for the first time. I have
worked around it with the following snippet:

(defun sanityinc/reload-previously-loaded-with-load-path-updated (orig pkg-desc)
  (let ((load-path (cons (package-desc-dir pkg-desc) load-path)))
    (funcall orig pkg-desc)))

(advice-add 'package--reload-previously-loaded :around
            'sanityinc/reload-previously-loaded-with-load-path-updated)