Subject: Re: bug#74040: `require-with-check` signals error for `project`

From: Stefan Monnier <[email-masked]>
Date: Sun, 27 Oct 2024 12:43:27 -0400

> One approach is to expose the `prefer` option of `openp` to
> `locate-file` so we can use it in `require-with-check`, as in the
> patch below.

Another is to replace the `assoc` check with one that is more lenient,
ignoring difference in file extensions.  E.g. the patch below.
This makes the change more localized, at the cost of making
`require-with-check` slower and less strict.

WDYT?

        Stefan
diff --git a/lisp/files.el b/lisp/files.el
index a81f742bbb4..a5177250f45 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1277,10 +1280,19 @@ require-with-check
     ;; file, so we're done.
     (when (eq lh load-history)
       ;; If `require' did nothing, we need to make sure that was warranted.
-      (let ((fn (locate-file (or filename (symbol-name feature))
-                             load-path (get-load-suffixes))))
+      (let* ((fn (locate-file (or filename (symbol-name feature))
+                              load-path (get-load-suffixes) nil
+                              )) ;; load-prefer-newer
+             (fn (if (string-match
+                      (concat (regexp-opt (get-load-suffixes)) "\\'") fn)
+                     (concat (substring fn 0 (match-end 0)) ".")
+                   fn))
+             (lh load-history))
+        (while (and lh (let ((file (car-safe (car lh))))
+                         (not (and file (string-prefix-p fn file)))))
+          (setq lh (cdr lh)))
         (cond
-         ((assoc fn load-history) nil)  ;We loaded the right file.
+         (lh nil)  ;We loaded the right file.
          ((eq noerror 'reload) (load fn nil 'nomessage))
          ((and fn (memq feature features))
           (funcall (if noerror #'warn #'error)