1.0.45.31: make COPY-PPRINT-DISPATCH have access to a pristine table
[sbcl.git] / tests / mop.impure.lisp
index a2c85ef..35118d0 100644 (file)
 ;;;; However, this seems a good a way as any of ensuring that we have
 ;;;; no regressions.
 
+(load "test-util.lisp")
+
 (defpackage "MOP-TEST"
-  (:use "CL" "SB-MOP" "ASSERTOID"))
+  (:use "CL" "SB-MOP" "ASSERTOID" "TEST-UTIL"))
 
 (in-package "MOP-TEST")
 \f
   (: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))))
+\f
 ;;;; success