emacseieio

unbound slot only in child class but not in parent


In the code below I get an error: (unbound-slot b "#<b b-4c6d8d46>" b-slot oref)

I do not understand why this is the case. The error only occurs for the slot in the child class b but not in the parent class a.

What should I do to make sure b-slot is bound so I can add values to it?

(defclass a ()
  ((a-slot :initform nil :type list)))

(defclass b (a)
  ((b-slot :init-form nil :type list)))

(let ((obj (b)))
  (push 1 (oref obj a-slot))
  (push 2 (oref obj b-slot)))

Solution

  • There is a mistake in the declaration for the b class.

    The Slot option is initform not init-form.

    (defclass b (a)
      ((b-slot :initform nil :type list)))
    
    
    (let ((obj (b)))
      (push 1 (oref obj a-slot))
      (push 2 (oref obj b-slot))
         (message "a-slot: %s" (oref obj a-slot)) 
         (message "b-slot: %s" (oref obj b-slot)) ; complete log available in the *MESSAGE* buffer.
        )