results in a STYLE-WARNING:
undefined-function
SB-SLOT-ACCESSOR-NAME::|COMMON-LISP-USER A-CLASS-X slot READER|
- b. DEFGENERIC does not check lambda list syntax; from the REPL:
- * (defgeneric gf ("a" #p"b"))
-
- #<STANDARD-GENERIC-FUNCTION GF (0)>
- *
c. the examples in CLHS 7.6.5.1 (regarding generic function lambda
lists and &KEY arguments) do not signal errors when they should.
LOGAND and stack-allocated arguments. (thanks to Raymond Toy)
* Bug fix: We no longer segfault on passing a non-FILE-STREAM stream
to a functions expecting a PATHNAME-DESIGNATOR.
+ * Bug fix: DEFGENERIC now enforces the ANSI restrictions on its
+ lambda lists. (thanks to Alexey Dejneka)
* Minor incompatible change: COMPILE-FILE-PATHNAME now merges its
OUTPUT-FILE argument with its INPUT-FILE argument, resulting in
behaviour analogous to RENAME-FILE. This puts its behaviour more
:state :read-only)
;; FIXME: Are COLLECTION and MUTABLE-COLLECTION used for anything
- ;; any more? COLLECTION is not defined in ANSI Common Lisp..
+ ;; any more? COLLECTION is not defined in ANSI Common Lisp.
+ ;; (Zhivago in #lisp IRC 2002-08-14 said that these things, and
+ ;; also GENERIC-FOO, are related to Dylan functionality and so
+ ;; truly are irrelevant these days.)
(collection :hierarchical-p nil :state :read-only)
(mutable-collection :state :read-only
:inherits (collection))
(in-package "SB-IMPL") ;(SB-IMPL, not SB!IMPL, since we're built in warm load.)
\f
(declaim (ftype (function (t stream)) describe-object))
-(defgeneric describe-object ((x t) stream))
+(defgeneric describe-object (x stream))
(defun describe (x &optional (stream-designator *standard-output*))
#+sb-doc
(defmethod describe-object ((x function) s)
(%describe-fun x s :function))
-(defgeneric describe-symbol-fdefinition (function stream &key (name nil) ))
+(defgeneric describe-symbol-fdefinition (function stream &key name))
(defmethod describe-symbol-fdefinition ((fun function) stream &key name)
(%describe-fun fun stream :function name))
(etypecase name
(symbol (funcall function name))
(list
- ;; We call this just for the side effect of checking that
- ;; NAME is a legal function name:
- (fun-name-block-name name)
+ (legal-fun-name-or-type-error name)
;; Then we map onto it.
(funcall function name))
(string (let ((package (find-undeleted-package-or-lose name)))
\f
(defmacro defgeneric (fun-name lambda-list &body options)
(declare (type list lambda-list))
- (legal-fun-name-or-type-error fun-name)
+ (unless (legal-fun-name-p fun-name)
+ (error 'simple-program-error
+ :format-control "illegal generic function name ~S"
+ :format-arguments (list fun-name)))
+ (check-gf-lambda-list lambda-list)
(let ((initargs ())
(methods ()))
(flet ((duplicate-option (name)
:lambda-list lambda-list
:definition-source `((defgeneric ,fun-name) ,*load-truename*)
initargs))
+
+;;; As per section 3.4.2 of the ANSI spec, generic function lambda
+;;; lists have a number of limitations, which we check here.
+(defun check-gf-lambda-list (lambda-list)
+ (macrolet ((ensure (condition)
+ `(unless ,condition
+ (error "Invalid argument ~S in the generic function lambda list ~S."
+ it lambda-list))))
+ (process-lambda-list lambda-list
+ (&required (ensure (symbolp it)))
+ (&optional (ensure (or (symbolp it)
+ (and (consp it) (symbolp (car it)) (null (cdr it))))))
+ (&rest (ensure (symbolp it)))
+ (&key (ensure (or (symbolp it)
+ (and (consp it)
+ (or (symbolp (car it))
+ (and (consp (car it))
+ (symbolp (caar it))
+ (symbolp (cadar it))
+ (null (cddar it))))
+ (null (cdr it))))))
+ ((&aux (error "&AUX is not allowed in the generic function lambda list ~S."
+ lambda-list))))))
\f
(defmacro defmethod (&rest args &environment env)
(multiple-value-bind (name qualifiers lambda-list body)
(defgeneric get-method (generic-function
qualifiers
specializers
- &optional (errorp t)))
+ &optional errorp))
(defgeneric find-method (generic-function
qualifiers
specializers
- &optional (errorp t)))
+ &optional errorp))
(defgeneric remove-named-method (generic-function-name
argument-specifiers
(defmethod stream-start-line-p ((stream fundamental-character-output-stream))
(eql (stream-line-column stream) 0))
-(defgeneric stream-write-string (stream string &optional (start 0) end)
+(defgeneric stream-write-string (stream string &optional start end)
#+sb-doc
(:documentation
"This is used by WRITE-STRING. It writes the string to the stream,
`(setf ,name))
(defsetf slot-value set-slot-value)
+\f
+(defun misplaced-lambda-list-keyword (lambda-list keyword)
+ (error "Lambda list keyword ~S is misplaced in ~S." keyword lambda-list))
+
+(defmacro process-lambda-list (lambda-list &rest clauses)
+ ;; (process-lambda-list '(a b &optional (c 1))
+ ;; (&required)
+ ;; ((&optional (print "Started processing optional arguments"))
+ ;; (format "Optional argument: ~S~%" it))
+ ;; (&rest (print "Rest")))
+ (let ((clauses (loop for clause in clauses
+ collect
+ (cond ((symbolp (car clause))
+ `(,(car clause) nil . ,(cdr clause)))
+ ((consp (car clause))
+ `(,(caar clause) ,(cdar clause) . ,(cdr clause)))
+ (t (error "Invalid clause format: ~S." clause)))))
+ (ll (gensym "LL"))
+ (state (gensym "STATE"))
+ (restp (gensym "RESTP"))
+ (check-state (gensym "CHECK-STATE")))
+ `(let ((,ll ,lambda-list)
+ (,state '&required)
+ (,restp nil))
+ (dolist (it ,ll)
+ (flet ((,check-state (possible)
+ (unless (memq ,state possible)
+ (misplaced-lambda-list-keyword ,ll it))))
+ (cond ((memq it lambda-list-keywords)
+ (case it
+ (&optional (,check-state '(&required))
+ ,@(cadr (assoc '&optional clauses)))
+ (&rest (,check-state '(&required &optional))
+ ,@(cadr (assoc '&rest clauses)))
+ (&key (,check-state '(&required &optional &rest))
+ (when (and (eq ,state '&rest)
+ (not ,restp))
+ (error "Omitted &REST variable in ~S." ,ll))
+ ,@(cadr (assoc '&key clauses)))
+ (&allow-other-keys (,check-state '(&key))
+ ,@(cadr (assoc '&allow-other-keys clauses)))
+ (&aux (when (and (eq ,state '&rest)
+ (not ,restp))
+ (error "Omitted &REST variable in ~S." ,ll))
+ ,@(cadr (assoc '&aux clauses)))
+ (t (error "Unsupported lambda list keyword ~S in ~S."
+ it ,ll)))
+ (setq ,state it))
+ (t (case ,state
+ (&required ,@(cddr (assoc '&required clauses)))
+ (&optional ,@(cddr (assoc '&optional clauses)))
+ (&rest (when ,restp
+ (error "Too many variables after &REST in ~S." ,ll))
+ (setq ,restp t)
+ ,@(cddr (assoc '&rest clauses)))
+ (&key ,@(cddr (assoc '&key clauses)))
+ (&allow-other-keys (error "Variable ~S after &ALLOW-OTHER-KEY in ~S."
+ it ,ll))
+ (&aux ,@(cddr (assoc '&aux clauses))))))))
+ (when (and (eq ,state '&rest)
+ (not ,restp))
+ (error "Omitted &REST variable in ~S." ,ll)))))
(/show "finished with pcl/macros.lisp")
(defmethod wiggle ((a struct-a))
(+ (struct-a-x a)
(struct-a-y a)))
-(defgeneric jiggle ((arg t)))
+(defgeneric jiggle (arg))
(defmethod jiggle ((a struct-a))
(- (struct-a-x a)
(struct-a-y a)))
;;; Compiling DEFGENERIC should prevent "undefined function" style
;;; warnings from code within the same file.
-(defgeneric gf-defined-in-this-file ((x number) (y number)))
+(defgeneric gf-defined-in-this-file (x y))
(defun function-using-gf-defined-in-this-file (x y n)
(unless (minusp n)
(gf-defined-in-this-file x y)))
(ignore-errors (progn ,@body))
(declare (ignore res))
(typep condition 'error))))
-
(assert (expect-error
(macroexpand-1
'(defmethod foo0 ((x t) &rest) nil))))
-
(assert (expect-error (defgeneric foo1 (x &rest))))
(assert (expect-error (defgeneric foo2 (x a &rest))))
-
(defgeneric foo3 (x &rest y))
(defmethod foo3 ((x t) &rest y) nil)
(defmethod foo4 ((x t) &key y &rest z) nil)
-(defgeneric foo4 (x &key y &rest z))
-
+(defgeneric foo4 (x &rest z &key y))
(assert (expect-error (defgeneric foo5 (x &rest))))
(assert (expect-error (macroexpand-1 '(defmethod foo6 (x &rest)))))
+;;; more lambda-list checking
+;;;
+;;; DEFGENERIC lambda lists are subject to various limitations, as per
+;;; section 3.4.2 of the ANSI spec. Since Alexey Dejneka's patch for
+;;; bug 191-b ca. sbcl-0.7.22, these limitations should be enforced.
+(labels ((coerce-to-boolean (x)
+ (if x t nil))
+ (%like-or-dislike (expr expected-failure-p)
+ (declare (type boolean expected-failure-p))
+ (format t "~&trying ~S~%" expr)
+ (multiple-value-bind (fun warnings-p failure-p)
+ (compile nil
+ `(lambda ()
+ ,expr))
+ (declare (ignore fun))
+ ;; In principle the constraint on WARNINGS-P below seems
+ ;; reasonable, but in practice we get warnings about
+ ;; undefined functions from the DEFGENERICs, apparently
+ ;; because the DECLAIMs which ordinarily prevent such
+ ;; warnings don't take effect because EVAL-WHEN
+ ;; (:COMPILE-TOPLEVEL) loses its magic when compiled
+ ;; within a LAMBDA. So maybe we can't test WARNINGS-P
+ ;; after all?
+ ;;(unless expected-failure-p
+ ;; (assert (not warnings-p)))
+ (assert (eq (coerce-to-boolean failure-p) expected-failure-p))))
+ (like (expr)
+ (%like-or-dislike expr nil))
+ (dislike (expr)
+ (%like-or-dislike expr t)))
+ ;; basic sanity
+ (dislike '(defgeneric gf-for-ll-test-0 ("a" #p"b")))
+ (like '(defgeneric gf-for-ll-test-1 ()))
+ (like '(defgeneric gf-for-ll-test-2 (x)))
+ ;; forbidden default or supplied-p for &OPTIONAL or &KEY arguments
+ (dislike '(defgeneric gf-for-ll-test-3 (x &optional (y 0))))
+ (like '(defgeneric gf-for-ll-test-4 (x &optional y)))
+ (dislike '(defgeneric gf-for-ll-test-5 (x y &key (z :z z-p))))
+ (like '(defgeneric gf-for-ll-test-6 (x y &key z)))
+ (dislike '(defgeneric gf-for-ll-test-7 (x &optional (y 0) &key z)))
+ (like '(defgeneric gf-for-ll-test-8 (x &optional y &key z)))
+ (dislike '(defgeneric gf-for-ll-test-9 (x &optional y &key (z :z))))
+ (like '(defgeneric gf-for-ll-test-10 (x &optional y &key z)))
+ (dislike '(defgeneric gf-for-ll-test-11 (&optional &key (k :k k-p))))
+ (like '(defgeneric gf-for-ll-test-12 (&optional &key k)))
+ ;; forbidden &AUX
+ (dislike '(defgeneric gf-for-ll-test-13 (x y z &optional a &aux g h)))
+ (like '(defgeneric gf-for-ll-test-14 (x y z &optional a)))
+ ;; also can't use bogoDEFMETHODish type-qualifier-ish decorations
+ ;; on required arguments
+ (dislike '(defgeneric gf-for-11-test-15 ((arg t))))
+ (like '(defgeneric gf-for-11-test-16 (arg))))
+
;;; structure-class tests setup
(defclass structure-class-foo1 () () (:metaclass cl:structure-class))
(defclass structure-class-foo2 (structure-class-foo1)
;;; Until Pierre Mai's patch (sbcl-devel 2002-06-18, merged in
;;; sbcl-0.7.4.39) the :MOST-SPECIFIC-LAST option had no effect.
-(defgeneric bug180 ((x t))
+(defgeneric bug180 (x)
(:method-combination list :most-specific-last))
(defmethod bug180 list ((x number))
'number)
;;; for internal versions, especially for internal versions off the
;;; main CVS branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.7.6.22"
+"0.7.6.23"