+\f
+;;; we should be able to make classes with silly names
+(make-instance 'standard-class :name 3)
+(defclass foo () ())
+(reinitialize-instance (find-class 'foo) :name '(a b))
+\f
+;;; classes (including anonymous ones) and eql-specializers should be
+;;; allowed to be specializers.
+(defvar *anonymous-class*
+ (make-instance 'standard-class
+ :direct-superclasses (list (find-class 'standard-object))))
+(defvar *object-of-anonymous-class*
+ (make-instance *anonymous-class*))
+(eval `(defmethod method-on-anonymous-class ((obj ,*anonymous-class*)) 41))
+(assert (eql (method-on-anonymous-class *object-of-anonymous-class*) 41))
+(eval `(defmethod method-on-anonymous-class
+ ((obj ,(intern-eql-specializer *object-of-anonymous-class*)))
+ 42))
+(assert (eql (method-on-anonymous-class *object-of-anonymous-class*) 42))
+\f
+;;; accessors can cause early finalization, which caused confusion in
+;;; the system, leading to uncompileable TYPEP problems.
+(defclass funcallable-class-for-typep ()
+ ((some-slot-with-accessor :accessor some-slot-with-accessor))
+ (:metaclass funcallable-standard-class))
+(compile nil '(lambda (x) (typep x 'funcallable-class-for-typep)))
+\f
+;;; even anonymous classes should be valid types
+(let* ((class1 (make-instance 'standard-class :direct-superclasses (list (find-class 'standard-object))))
+ (class2 (make-instance 'standard-class :direct-superclasses (list class1))))
+ (assert (subtypep class2 class1))
+ (assert (typep (make-instance class2) class1)))
+\f
+;;; ensure-class got its treatment of :metaclass wrong.
+(ensure-class 'better-be-standard-class :direct-superclasses '(standard-object)
+ :metaclass 'standard-class
+ :metaclass 'funcallable-standard-class)
+(assert (eq (class-of (find-class 'better-be-standard-class))
+ (find-class 'standard-class)))
+
+;;; CLASS-SLOTS should signal an error for classes that are not yet
+;;; finalized. Reported by Levente Meszaros on sbcl-devel.
+(defclass has-slots-but-isnt-finalized () (a b c))
+(let ((class (find-class 'has-slots-but-isnt-finalized)))
+ (assert (not (sb-mop:class-finalized-p class)))
+ (assert (raises-error? (sb-mop:class-slots class) sb-kernel::reference-condition)))
+
+;;; Check that MAKE-METHOD-LAMBDA which wraps the original body doesn't
+;;; break RETURN-FROM.
+(defclass wrapped-generic (standard-generic-function)
+ ()
+ (:metaclass sb-mop:funcallable-standard-class))
+
+(defmethod sb-mop:make-method-lambda ((gf wrapped-generic) method lambda env)
+ (call-next-method gf method
+ `(lambda ,(second lambda)
+ (flet ((default () :default))
+ ,@(cddr lambda)))
+ env))
+
+(defgeneric wrapped (x)
+ (:generic-function-class wrapped-generic))
+
+(defmethod wrapped ((x cons))
+ (return-from wrapped (default)))
+
+(with-test (:name :make-method-lambda-wrapping+return-from)
+ (assert (eq :default (wrapped (cons t t)))))
+
+(with-test (:name :slow-method-is-fboundp)
+ (assert (fboundp '(sb-pcl::slow-method wrapped (cons))))
+ (assert (eq :default (funcall #'(sb-pcl::slow-method wrapped (cons)) (list (cons t t)) nil))))
+
+;;; Check that SLOT-BOUNDP-USING-CLASS doesn't confuse MAKE-INSTANCE
+;;; optimizations.
+(defclass sbuc-mio-test-class (standard-class)
+ ())
+(defmethod validate-superclass ((class sbuc-mio-test-class)
+ (superclass standard-class))
+ t)
+(defvar *sbuc-counter* 0)
+(defmethod slot-boundp-using-class ((class sbuc-mio-test-class)
+ (object t)
+ (slot standard-effective-slot-definition))
+ (incf *sbuc-counter*)
+ (call-next-method))
+(defclass sbuc-mio-test-object ()
+ ((slot :initform 5 :accessor a-slot))
+ (:metaclass sbuc-mio-test-class))
+(with-test (:name :sbuc-mio-test)
+ (assert (= 5 (funcall
+ (compile
+ nil
+ `(lambda ()
+ (let ((object (make-instance 'sbuc-mio-test-object)))
+ (slot-value object 'slot)))))))
+ (assert (= 1 *sbuc-counter*)))
+
+;;; Redefining classes so that slot definition class changes.
+(defclass func-slot-class (standard-class)
+ ())
+
+(defmethod sb-mop:validate-superclass ((class func-slot-class) (super standard-class))
+ t)