safepoint: Remove unused context argument.
[sbcl.git] / tests / mop-32.impure.lisp
blob8791731e857dbace9f0a6a129832568a8a04e1ea
1 ;;;; Handling errors in UPDATE-INSTANCE-FOR-REDEFINED-CLASS
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (defclass foo-class (standard-class) ())
16 (defmethod sb-mop:validate-superclass ((c foo-class) (s standard-class)) t)
18 (defclass foo-object (standard-object) ())
20 (defmethod shared-initialize :around ((class foo-class) slot-names
21 &rest rest
22 &key direct-superclasses)
23 (apply #'call-next-method
24 class slot-names
25 :direct-superclasses
26 (append (remove (find-class 'standard-object) direct-superclasses)
27 (list (find-class 'foo-object)))
28 rest))
30 (defmethod update-instance-for-redefined-class :before
31 ((instance foo-object)
32 added-slots discarded-slots
33 property-list
34 &rest initargs)
35 (declare (ignore initargs))
36 ;; This U-I-F-R-C is meant to always signal an error.
37 (error "expected failure"))
39 ;;; Define FOO.
40 (defclass foo () () (:metaclass foo-class))
42 ;;; Make an instance of FOO.
43 (defparameter *foo* (make-instance 'foo))
45 ;;; Redefine FOO, causing *FOO* to become obsolete.
46 (defclass foo ()
47 ((slot :initform 42))
48 (:metaclass foo-class))
50 ;;; This should result in an "expected failure" error, because
51 ;;; the instance is obsolete.
52 (multiple-value-bind (result error)
53 (ignore-errors (slot-value *foo* 'slot))
54 (assert (null result))
55 (assert (string= (princ-to-string error) "expected failure")))
57 ;;; This should *also* result in an "expected failure" error, because after
58 ;;; the previous U-I-F-R-C call made a non-local exit, the instance should be
59 ;;; automatically made obsolete once more.
60 (multiple-value-bind (result error)
61 (ignore-errors (slot-value *foo* 'slot))
62 (assert (null result))
63 (assert (string= (princ-to-string error) "expected failure")))
65 ;;; Redefine the U-I-F-R-C method to no longer signal an error.
66 (defmethod update-instance-for-redefined-class :before
67 ((instance foo-object)
68 added-slots discarded-slots
69 property-list
70 &rest initargs)
71 (declare (ignore initargs)))
73 ;;; Instance is now updateable. It should now be possible to access the new slot
74 ;;; and fetch its initform-initialized value.
75 (assert (= 42 (slot-value *foo* 'slot)))