&key checking in methods and eql specializers

Bug #1760987 reported by Stas Boukarev on 2018-04-03
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
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://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#applicable_method>)

=> "Applicable methods" include all method corresponding to parameters
of a function call.

CLHS 7.6.5
(<http://www.lispworks.com/documentation/HyperSpec/Body/07_fe.htm>)
"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://www.lispworks.com/documentation/HyperSpec/Body/07_fea.htm>)

=> Examples

CLHS 7.6.4 is less clear on theses subjects.

Syll

Tags: pcl Edit Tag help

I think you are right.

Here's a draft patch to try to fix the problem.

committed as 94edc6c8e78f743846f7c1faa5c145cc3ca3415f. Thank you!

Changed in sbcl:
status: Triaged → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Patches