- (old-class-slots (wrapper-class-slots old-wrapper)))
-
- ;; "The values of local slots specified by both the class CTO and
- ;; CFROM are retained. If such a local slot was unbound, it
- ;; remains unbound."
- (let ((new-position 0))
- (dolist (new-slot new-layout)
- (let ((old-position (posq new-slot old-layout)))
- (when old-position
- (setf (clos-slots-ref new-slots new-position)
- (clos-slots-ref old-slots old-position))))
- (incf new-position)))
-
- ;; "The values of slots specified as shared in the class CFROM and
- ;; as local in the class CTO are retained."
- (dolist (slot-and-val old-class-slots)
- (let ((position (posq (car slot-and-val) new-layout)))
- (when position
- (setf (clos-slots-ref new-slots position) (cdr slot-and-val)))))
+ (old-class-slots (wrapper-class-slots old-wrapper))
+ (safe (safe-p new-class)))
+
+ (flet ((set-value (value pos)
+ (when safe
+ (let ((spec (nth pos new-layout)))
+ (assert (typep value (cdr spec)) (value)
+ "~@<Error changing class. Current value in slot ~S ~
+ of an instance of ~S is ~S, which does not match the new ~
+ slot type ~S in class ~S.~:@>"
+ (car spec) old-class value
+ (cdr spec) new-class)))
+ (setf (clos-slots-ref new-slots pos) value)))
+ ;; "The values of local slots specified by both the class CTO and
+ ;; CFROM are retained. If such a local slot was unbound, it
+ ;; remains unbound."
+ (let ((new-position 0))
+ (dolist (new-slot new-layout)
+ (let* ((name (car new-slot))
+ (old-position (position name old-layout :key #'car)))
+ (when old-position
+ (set-value (clos-slots-ref old-slots old-position)
+ new-position)))
+ (incf new-position)))
+
+ ;; "The values of slots specified as shared in the class CFROM and
+ ;; as local in the class CTO are retained."
+ (dolist (slot-and-val old-class-slots)
+ (let ((position (position (car slot-and-val) new-layout :key #'car)))
+ (when position
+ (set-value (cdr slot-and-val) position)))))