X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fmop.impure.lisp;h=35118d0cabd825ec633f47883b51cb479a0abaa9;hb=a51d83191034919bc76367268929e234d62164db;hp=e69a1ea6a41ffc1182b3fefa60726552504dfc13;hpb=fb03344c5e8388e0b16512f1cb662d8cf5d13972;p=sbcl.git diff --git a/tests/mop.impure.lisp b/tests/mop.impure.lisp index e69a1ea..35118d0 100644 --- a/tests/mop.impure.lisp +++ b/tests/mop.impure.lisp @@ -15,8 +15,10 @@ ;;;; 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") @@ -486,4 +488,71 @@ (defclass foo () ()) (reinitialize-instance (find-class 'foo) :name '(a b)) +;;; 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)) + +;;; 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))) + +;;; 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))) + +;;; 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)))) + ;;;; success