Better warnings for keyword arguments in presence of :betfore, :after methods

Bug #1907273 reported by Paul F. Dietz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Wishlist
Unassigned

Bug Description

When the set of keyword arguments for the methods of a generic function using standard method combination are known at compile time, sbcl will warn if a keyword argument in a call to that function is not in that set.

This warning is disabled if &allow-other-keys is present in the defgeneric or in any method definition for the function. However, it's still possible to give the warning if &allow-other-keys only occurs on :before and :after methods, as these will always be accompanied by an invocation of a primary or :around method. Enhance the warning processing to ignore &allow-other-keys on :before and :after methods.

Revision history for this message
Stas Boukarev (stassats) wrote :

Can you provide an example?

Revision history for this message
Paul F. Dietz (paul-f-dietz) wrote :

(in-package :cl-user)

(defgeneric f1 (x &key))
(defmethod f1 ((x symbol) &key k) (list x k))

(defgeneric f2 (x &key))
(defmethod f2 ((x symbol) &key k) (list x k))
(defmethod f2 :before ((x t) &key &allow-other-keys)
  (format t "f2 before method~%"))

(defgeneric f3 (x &key))
(defmethod f3 ((x symbol) &key k) (list x k))
(defmethod f3 :after ((x t) &key &allow-other-keys)
  (format t "f3 after method~%"))

compile nil '(lambda (x) (f1 x :bad 1))) ==>
; in: LAMBDA (X)
; (F1 X :BAD 1)
;
; caught STYLE-WARNING:
; :BAD is not a known argument keyword.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
#<FUNCTION (LAMBDA (X)) {52CDC6CB}>
T
NIL

(compile nil '(lambda (x) (f2 x :bad 1))) ==>
#<FUNCTION (LAMBDA (X)) {52CDC77B}>
NIL
NIL

(compile nil '(lambda (x) (f3 x :bad 1)))
#<FUNCTION (LAMBDA (X)) {52CDC82B}>
NIL
NIL

Stas Boukarev (stassats)
Changed in sbcl:
importance: Undecided → Wishlist
Revision history for this message
Stas Boukarev (stassats) wrote :

But it says

5. The use of &allow-other-keys need not be consistent across lambda lists. If &allow-other-keys is mentioned in the lambda list of any applicable method
    or of the generic function, any keyword arguments may be mentioned in the call to the generic function.

No mention that it applies only to primary methods.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.