X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fclos.impure-cload.lisp;h=26dd5948e0d6ce4555b423dda0840ecac90e5aa1;hb=b3e7d6608689a639cb774e2ce15bb5bacaed5179;hp=beaa4ee4530a4b1545092152ea68f95d83fcd1e8;hpb=ded2af78dc3f04e6b0c41817a712516aa4caf62d;p=sbcl.git diff --git a/tests/clos.impure-cload.lisp b/tests/clos.impure-cload.lisp index beaa4ee..26dd594 100644 --- a/tests/clos.impure-cload.lisp +++ b/tests/clos.impure-cload.lisp @@ -62,6 +62,78 @@ (defmethod baz ((x specializer2)) x) (defmethod baz ((x specializer1)) x) (assert (typep (baz (make-instance 'specializer1)) 'specializer1)) + +;;; ... and from McCLIM, another test case: +(defclass specializer1a (specializer2a specializer2b) ()) +(defclass specializer2a () ()) +(defmethod initialize-instance :after + ((obj specializer2a) &key &allow-other-keys) + (print obj)) + +;;; in a similar vein, we should be able to define methods on classes +;;; that are effectively unknown to the type system: +(sb-mop:ensure-class 'unknown-type) +(defmethod method-on-unknown ((x unknown-type)) x) +;;; (we can't call it without defining methods on allocate-instance +;;; etc., but we should be able to define it). + +;;; the ctor MAKE-INSTANCE optimizer used not to handle duplicate +;;; initargs... +(defclass dinitargs-class1 () + ((a :initarg :a))) +(assert (= (slot-value (make-instance 'dinitargs-class1 :a 1 :a 2) 'a) 1)) + +(defclass dinitargs-class2 () + ((b :initarg :b1 :initarg :b2))) +(assert (= (slot-value (make-instance 'dinitargs-class2 :b2 3 :b1 4) 'b) 3)) +;;; ... or default-initargs when the location was already initialized +(defvar *definitargs-counter* 0) +(defclass definitargs-class () + ((a :initarg :a :initarg :a2)) + (:default-initargs :a2 (incf *definitargs-counter*))) +(assert (= (slot-value (make-instance 'definitargs-class) 'a) 1)) +(assert (= (slot-value (make-instance 'definitargs-class :a 0) 'a) 0)) +(assert (= *definitargs-counter* 2)) + +;;; inherited local -> shared slot initforms +;; (adapted from Paul F. Dietz's test suite DEFCLASS-0211.1) +(defclass shared-to-local-initform-super () + ((redefined :allocation :instance :initform 'orig-initform))) +(defclass shared-to-local-initform-sub (shared-to-local-initform-super) + ((redefined :allocation :class))) +(assert (slot-boundp (make-instance 'shared-to-local-initform-sub) 'redefined)) +(assert (eq 'orig-initform + (slot-value (make-instance 'shared-to-local-initform-sub) 'redefined))) + +(defgeneric no-ignored-warnings (x y)) +(handler-case + (eval '(defmethod no-ignored-warnings ((x t) (y t)) + (declare (ignore x y)) nil)) + (style-warning (c) (error c))) +(handler-case + (eval '(defmethod no-ignored-warnings ((x number) (y t)) + (declare (ignore x y)) (setq *print-level* nil))) + (style-warning (c) (error c))) +(handler-case + (eval '(defmethod no-ignored-warnings ((x fixnum) (y t)) + (declare (ignore x)) (setq y 'foo))) + (style-warning (c) (error c))) + +;;; from Axel Schairer on cmucl-imp 2004-08-05 +(defclass class-with-symbol-initarg () + ((slot :initarg slot))) +(defmethod initialize-instance :after + ((x class-with-symbol-initarg) &rest initargs &key &allow-other-keys) + (unless (or (null initargs) + (eql (getf initargs 'slot) + (slot-value x 'slot))) + (error "bad bad bad"))) +(defun make-thing (arg) + (make-instance 'class-with-symbol-initarg 'slot arg)) +(defun make-other-thing (slot arg) + (make-instance 'class-with-symbol-initarg slot arg)) +(assert (eql (slot-value (make-thing 1) 'slot) 1)) +(assert (eql (slot-value (make-other-thing 'slot 2) 'slot) 2)) ;;; success -(sb-ext:quit :unix-status 104) \ No newline at end of file +(sb-ext:quit :unix-status 104)