]> git.eshelyaron.com Git - emacs.git/commitdiff
(cl-generic-define-method): Try and fix bug#77464
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 13 Apr 2025 16:45:54 +0000 (12:45 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sun, 13 Apr 2025 21:02:59 +0000 (23:02 +0200)
* lisp/emacs-lisp/cl-generic.el (cl-generic-define-method): Don't set
the function to `dummy`, even temporarily.

(cherry picked from commit 19913b1567940b8af5bfcef5c6efe19a3656e66b)

lisp/emacs-lisp/cl-generic.el

index 71538a653bc298ae25dc7f322baeca43117e5827..c05feb20126b628648d8b0ee7d507a422e7bc228 100644 (file)
@@ -643,22 +643,24 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
           ;; FIXME: Try to avoid re-constructing a new function if the old one
           ;; is still valid (e.g. still empty method cache)?
           (gfun (cl--generic-make-function generic)))
-      (unless (symbol-function sym)
-        (defalias sym 'dummy))   ;Record definition into load-history.
       (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
                                      (cl--generic-name generic)
                                      qualifiers specializers))
                   current-load-list :test #'equal)
       (let ((old-adv-cc (get-advertised-calling-convention
-                         (symbol-function sym)))
-            ;; Prevent `defalias' from recording this as the definition site of
-            ;; the generic function.
-            current-load-list)
+                         (symbol-function sym))))
         (when (listp old-adv-cc)
-          (set-advertised-calling-convention gfun old-adv-cc nil))
-        ;; But do use `defalias', so that it interacts properly with nadvice,
-        ;; e.g. for tracing/debug-on-entry.
-        (defalias sym gfun)))))
+          (set-advertised-calling-convention gfun old-adv-cc nil)))
+      (if (not (symbol-function sym))
+          ;; If this is the first definition, use it as "the definition site of
+          ;; the generic function" since we don't know if a `cl-defgeneric'
+          ;; will follow or not.
+          (defalias sym gfun)
+        ;; Prevent `defalias' from recording this as the definition site of
+        ;; the generic function.  But do use `defalias', so it interacts
+        ;; properly with nadvice, e.g. for ;; tracing/debug-on-entry.
+        (let (current-load-list)
+          (defalias sym gfun))))))
 
 (defvar cl--generic-dispatchers (make-hash-table :test #'equal))