Subject: Re: bug#74289: 30.0.92; `require-with-check' fails on non-existing files

From: Stefan Monnier <[email-masked]>
Date: Sun, 10 Nov 2024 12:38:51 -0500

> `require-with-check' fails since
> 0aae02a3741c397d6952e3128d434827aca0f912 on non-existing files.
>
> See the CI run of the Compat test suite:
>
> https://github.com/emacs-compat/compat/actions/runs/11763132765/job/32766767667
>
> This call fails:
>
> (require-with-check 'compat-does-not-exist nil 'noerror)

Oops, can you confirm that the patch below works for you?

        Stefan

diff --git a/lisp/files.el b/lisp/files.el
index c3fce9f15f9..0d998e6e18e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1288,10 +1306,11 @@ require-with-check
              ;; we did load "it".  (bug#74040)
              ;; So use a "permissive" search which doesn't pay attention to
              ;; differences between file extensions.
-             (prefix (if (string-match
-                          (concat (regexp-opt (get-load-suffixes)) "\\'") fn)
-                         (concat (substring fn 0 (match-beginning 0)) ".")
-                       fn))
+             (prefix (when fn
+                       (if (string-match
+                            (concat (regexp-opt (get-load-suffixes)) "\\'") fn)
+                           (concat (substring fn 0 (match-beginning 0)) ".")
+                         fn)))
              (lh load-history))
         (while (and lh (let ((file (car-safe (car lh))))
                          (not (and file (string-prefix-p prefix file)))))