&key checking in methods and eql specializers
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Medium
|
Unassigned |
Bug Description
Reported by Syll on sbcl-bugs@
Hello
I think I have found a strange behaviour in SBCL methods.
While running this code :
(defgeneric f (val &key p1))
(defmethod f ((val (eql 1)) &key p1 p2)
(print p1)
(print p2))
(defmethod f ((val (eql 2)) &key p1 p3)
(print p1)
(print p3))
(f 1 :p2 22) ; ok (seems correct)
(f 1 :p3 22) ; ok (seems wrong)
(f 1 :p4 22) ; error (seems correct)
The second call to (f) does not signal an error. I would have expected
an error because p3 does not appear in any applicable method during
this call to generic function f.
Clisp does signal an error for this second call.
This example (adapted form CLHS 7.6.5.1) does work as I expected (signal
an error) :
(defclass character-class () ())
(defclass picture-class () ())
(defmethod width ((c character-class) &key font) nil)
(defmethod width ((p picture-class) &key pixel-size) nil)
(width (make-instance `character-class)
:font 'baskerville :pixel-size 10)
The difference in SBCL behaviours seems to be related to eql
specializer. Unless there is a special case for this specializers, I
think the second call from my first example should signal an error.
-------
If I understand correctly the specification :
CLHS glossary
(<http://
=> "Applicable methods" include all method corresponding to parameters
of a function call.
CLHS 7.6.5
(<http://
"When a generic function or any of its methods mentions &key in a
lambda list, the specific set of keyword arguments accepted by the
generic function varies according to the applicable methods."
and
"The set of keyword arguments accepted by the generic function for a
particular call is the union of the keyword arguments accepted by
all applicable methods and the keyword arguments mentioned after
&key in the generic function definition, if any."
=> Applicable methods are used to détermine which keyword parameters
are accepted for the call, all parameters involved in any applicable
methods are accepted.
CLHS 7.6.5.1
(<http://
=> Examples
CLHS 7.6.4 is less clear on theses subjects.
Syll
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
I think you are right.
Here's a draft patch to try to fix the problem.