Subject: Re: bug#50219: 28.0.50; Provide better errors when trying to specialize on optional args in generic methods

From: Eric Abrahamsen <[email-masked]>
Date: Thu, 26 Aug 2021 18:31:44 -0700

Lars Ingebrigtsen <[email-masked]> writes:

> Eric Abrahamsen <[email-masked]> writes:
>
>> - the manual section on "Generic Functions" could say explicitly that
>>   you can't specialize on optional arguments
>> - `eval'ling the `defmethod' form above could raise an error directly
>> - the compiler could say more explicitly what the problem is
>>
>> I'd favor all three of these changes!
>
> Me, too.

Here's a very simply manual patch.

I squinted long and hard at cl-generic.el, and I'm not confident about where
we'd put the error. In `cl--generic-lambda'?

>> Happy to implement what I can (maybe not the compiler part).
>
> I've added Stefan to the CCs; perhaps he has some comments.

He has already (kindly) made fun of me for my dumb code, so he ought to
be aware. :)

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 77d1465c87..6d4a93b08a 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1208,6 +1208,8 @@ Generic Functions
 Extensions for GNU Emacs Lisp}), or of one of its child classes.
 @end table
 
+Arguments marked as &optional can't be specialized on.
+
 Method definitions can make use of a new argument-list keyword,
 @code{&context}, which introduces extra specializers that test the
 environment at the time the method is run.  This keyword should appear