Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slots of custom slots are unbound on class redefinition #692

Open
lockie opened this issue Dec 26, 2024 · 0 comments
Open

Slots of custom slots are unbound on class redefinition #692

lockie opened this issue Dec 26, 2024 · 0 comments

Comments

@lockie
Copy link

lockie commented Dec 26, 2024

Hey! I've stumbled upon a problem on defining custom slot initargs using metaclass and then redefining the class. Let me illustrate with an example:

(ql:quickload :closer-mop)

(defclass custom-slot (c2mop:standard-direct-slot-definition)
  ((custom-arg
    :accessor custom-arg
    :initarg :custom-arg
    :initform nil)))

(defclass custom-metaclass (c2mop:standard-class) ())

(defmethod c2mop:validate-superclass ((class custom-metaclass)
                                      (super c2mop:standard-class))
  t)

(defmethod c2mop:direct-slot-definition-class ((class custom-metaclass)
                                               &rest initargs)
  (declare (ignore class initargs))
  (find-class 'custom-slot))

(defmethod shared-initialize ((class custom-metaclass) slots &rest rest)
  (declare (ignorable rest))
  (unless (eq slots t)
    (dolist (slot (c2mop:class-direct-slots class))
      (format t "s-i custom-arg = ~a~%" (custom-arg slot))))
  (call-next-method))

(defclass my-class ()
  ((my-slot
    :accessor my-slot
    :initform 42
    :type fixnum
    :custom-arg 'bar))
  (:metaclass custom-metaclass))

(defclass my-class ()
  ((my-slot
    :accessor my-slot
    :initform 42
    :type fixnum
    :custom-arg 'buzz))
  (:metaclass custom-metaclass))

(print (my-slot (make-instance 'my-class)))

This example works correctly with SBCL, CCL, ECL, Allegro CL and CLISP, but fails in ABCL saying

#<THREAD "interpreter" native {2F6A2561}>: Debugger invoked on condition of type UNBOUND-SLOT
  The slot CUSTOM-ARG is unbound in the object #<CUSTOM-SLOT {27D76870}>.

(this happens when SHARED-INITIALIZE is called because of class redefinition).

Does my modest knowledge of MOP fail me, or is it a bug in ABCL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant