unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50219: 28.0.50; Provide better errors when trying to specialize on optional args in generic methods
@ 2021-08-26 23:11 Eric Abrahamsen
  2021-08-27  0:34 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2021-08-26 23:11 UTC (permalink / raw)
  To: 50219


If you write a generic method and try to specialize on an &optional
argument, like so:

--8<---------------cut here---------------start------------->8---
(cl-defgeneric testy (arg1 &optional arg2))

(cl-defmethod testy ((arg1 string) &optional (arg2 integer))
  (message "Don't do this"))
--8<---------------cut here---------------end--------------->8---

It will behave weirdly when you try to call the function with a second
argument, but won't bark at you when you evaluate this form, and during
compilation will give you the error:

Warning: reference to free variable 'integer'

I was doing this with a specialization on an EIEIO class in EBDB, and
the warning was even weirder, but never mind that.

A few things could be done here:

- 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! Happy to implement what I can
(maybe not the compiler part).

Eric





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-08-30  3:33 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 23:11 bug#50219: 28.0.50; Provide better errors when trying to specialize on optional args in generic methods Eric Abrahamsen
2021-08-27  0:34 ` Lars Ingebrigtsen
2021-08-27  1:31   ` Eric Abrahamsen
2021-08-28 14:15     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-28 16:02       ` Lars Ingebrigtsen
2021-08-28 16:42         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-28 17:12           ` Lars Ingebrigtsen
2021-08-28 17:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-28 17:49               ` Lars Ingebrigtsen
2021-08-29  0:47               ` Eric Abrahamsen
2021-08-29 11:10                 ` Michael Heerdegen
2021-08-29 15:41                   ` Eric Abrahamsen
2021-08-29 19:16                     ` Michael Heerdegen
2021-08-30  3:33                       ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).