From: Stefan Monnier Date: Sun, 13 Apr 2025 16:45:54 +0000 (-0400) Subject: (cl-generic-define-method): Try and fix bug#77464 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6d7a14fbe7cffe15959a98f24fbbdea0addc0e7f;p=emacs.git (cl-generic-define-method): Try and fix bug#77464 * lisp/emacs-lisp/cl-generic.el (cl-generic-define-method): Don't set the function to `dummy`, even temporarily. (cherry picked from commit 19913b1567940b8af5bfcef5c6efe19a3656e66b) --- diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el index 71538a653bc..c05feb20126 100644 --- a/lisp/emacs-lisp/cl-generic.el +++ b/lisp/emacs-lisp/cl-generic.el @@ -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))