(in-package :cl-user)

(asdf:operate ' asdf:load-op 'cells)

(use-package :cells)

;;; For the problem to arise, it has to be a MODEL subclass.  No superclass
;;; (i.e. the hidden MODEL-OBJECT class as superclass) has no problem.

(defmodel my-model (model)
                 ((my-class-slot :cell nil :ALLOCATION :CLASS)))

(sb-mop:finalize-inheritance (find-class 'my-model))

(format t "> is the slot bound? ~S~%" (slot-boundp (find-class 'my-model) 'sb-pcl::prototype))

(format t "> what is the value of the slot? ~S~%" (slot-value (find-class 'my-model) 'sb-pcl::prototype))

;;; Actually, it is not the outer SETF that fails, it is the CLASS-PROTOTYPE
;;; reader function that somehow results in the SB-PCL::PROTOTYPE slot in the
;;; class object to become unbound.  I have no reason to believe that it is
;;; the logic in the CLASS-PROTOTYPE method (file std-class.lisp) that fails;
;;; an attempt to make a work-around by allocating the prototype slot explicitly
;;; fails in much the same way.

#+notworking (setf (slot-value (sb-mop:class-prototype (FIND-CLASS 'my-model))
			       'my-class-slot) 'a-value)

#+notworkingaround(setf (slot-value (find-class 'my-model) 'sb-pcl::prototype)
			(allocate-instance (find-class 'my-model)))

#+notworkingaround(setf (slot-value (find-class 'my-model) 'sb-pcl::prototype)
			(sb-pcl::allocate-standard-instance (sb-pcl::class-wrapper (find-class 'my-model))))