GNU bug report logs -
#50219
28.0.50; Provide better errors when trying to specialize on optional args in generic methods
Previous Next
Full log
View this message in rfc822 format
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
This bug report was last modified 3 years and 294 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.