Comment 1 for bug 473699

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote : Re: [Bug 473699] [NEW] "The value NIL is not of type SB-KERNEL:LAYOUT"

Hi,

 status confirmed
 importance medium
 tags clos mop pcl
 done

Lars Rune Nøstdal <email address hidden> writes:

> (defclass my-object ()
> ((id :type integer :reader id-of))
> (:metaclass my-class))
>
> [...]
> (defmethod initialize-instance ((class my-class) &rest initargs &key name direct-superclasses)
> (defmethod sb-mop:slot-value-using-class ((class my-class) (object my-object) eslotd)
> (if nil
> (setf (slot-value object 'id) 42)
> (call-next-method)))

As mentioned on IRC, this is not conforming MOP code: here you
instantiate MY-CLASS, then you define methods that are applicable to
objects of MY-CLASS; however, "Portable methods on specified generic
functions specialized to portable metaobject classes must be defined
before any instances of those classes (or any subclasses) are created,
either directly or indirectly by a call to make-instance." The main
workaround for you is I think to use (find-class 'my-object nil) in your
initialize-instance method.

That said, I was able to reduce this to a test case which I think is
legal MOP code and fails in the same way:

(defclass my-class (standard-class)
  ())
(defmethod sb-mop:validate-superclass
    ((class my-class) (super-class standard-class))
  t)
(defvar *foo*)
(defmethod sb-mop:slot-value-using-class
    ((class my-class) (object standard-object) eslotd)
  (if *foo*
      (setf (slot-value object 'id) 42)
      (call-next-method)))
(defclass my-object ()
  ((id :type integer :reader id-of))
  (:metaclass my-class)))
(defclass test (my-object)
  ((a :reader test-a))
  (:metaclass my-class))

I've Cced this to Pascal to ask him to check that the above is actually
legal MOP; in parallel, I'm working on a diagnosis and possible cure for
SBCL.

Cheers,

Christophe