Subject: bug#66342: Quote cl-generic-current-method-specializers

From: Thuna <[email-masked]>
Date: Tue, 04 Mar 2025 22:28:12 +0100

> If it's not useful, and anyways not used by anyone, I think it's better
> to get rid of it.
>
> Thuna, would you like to propose a patch that does that?

Hm, I still think it's a shame, but sure.  Something like the attached
patch should do the trick, though I've not tested it in the slightest.

>From 6d1fbc312fb2a73141a28c3abe7d94c88429f88a Mon Sep 17 00:00:00 2001
From: Thuna <[email-masked]>
Date: Tue, 4 Mar 2025 22:25:32 +0100
Subject: [PATCH] Remove `cl-generic-current-method-specializers'

* lisp/emacs-lisp/cl-generic.el (cl-generic-define-context-rewriter): Do
not bind `cl-generic-current-method-specializers' in the macro
environment.
(cl-generic-current-method-specializers): Remove macro.
---
 lisp/emacs-lisp/cl-generic.el | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index 11685d09d12..ea2bca4c1e0 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -339,11 +339,6 @@ cl-generic-define
     (setf (cl--generic-options generic) options)
     (cl--generic-make-function generic)))
 
-(defmacro cl-generic-current-method-specializers ()
-  "List of (VAR . TYPE) where TYPE is var's specializer.
-This macro can only be used within the lexical scope of a cl-generic method."
-  (error "cl-generic-current-method-specializers used outside of a method"))
-
 (defmacro cl-generic-define-context-rewriter (name args &rest body)
   "Define a special kind of context named NAME.
 Whenever a context specializer of the form (NAME . ARGS) appears,
@@ -391,17 +386,14 @@ cl-generic-define-context-rewriter
     "Make the lambda expression for a method with ARGS and BODY."
     (pcase-let* ((`(,spec-args . ,plain-args)
                   (cl--generic-split-args args))
-                 (fun `(cl-function (lambda ,plain-args ,@body)))
-                 (macroenv (cons `(cl-generic-current-method-specializers
-                                   . ,(lambda () spec-args))
-                                 macroexpand-all-environment)))
+                 (fun `(cl-function (lambda ,plain-args ,@body))))
       (require 'cl-lib)        ;Needed to expand `cl-flet' and `cl-function'.
       (when (assq 'interactive body)
         (message "Interactive forms not supported in generic functions: %S"
                  (assq 'interactive body)))
       ;; First macroexpand away the cl-function stuff (e.g. &key and
       ;; destructuring args, `declare' and whatnot).
-      (pcase (macroexpand fun macroenv)
+      (pcase (macroexpand fun macroexpand-all-environment)
         (`#'(lambda ,args . ,body)
          (let* ((parsed-body (macroexp-parse-body body))
                 (nm (make-symbol "cl--nm"))
@@ -412,7 +404,7 @@ cl-generic-define-context-rewriter
                         `(cl-flet ((cl-call-next-method ,cnm)
                                    (cl-next-method-p ,nmp))
                            ,@(cdr parsed-body))
-                        macroenv))
+                        macroexpand-all-environment))
                 ;; FIXME: Rather than `grep' after the fact, the
                 ;; macroexpansion should directly set some flag when cnm
                 ;; is used.
-- 
2.44.2