From 2d40d63d8738dc44b02ca61843fa61956958e84e Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 4 Nov 2023 17:11:32 -0400 Subject: [PATCH] Make EIEIO ':accessor' behave like ':reader' when reading * lisp/emacs-lisp/eieio.el (defclass): Remove 'slot-boundp' check for :accessor's getter Clones of instances of subclasses of 'eieio-instance-inheritor' don't delegate to their ':parent-instance' field when reading object fields using ':accessor'. Say I have this code: (defclass foo (eieio-instance-inheritor) ((x :initarg :x :accessor ref-x :reader get-x))) (setq obj1 (foo :x 4)) ; #s(foo eieio--unbound 4) (setq obj2 (clone obj1)) ; #s(foo #s(foo eieio--unbound 4) eieio--unbound) (ref-x obj1) ; 4, which is correct. (ref-x obj2) ; nil. This is what we want to fix. (get-x obj2) ; Gives us 4: access via the reader performs delegation. My impression is that ':accessor' should behave as if ':reader' and ':writer' had been provided separately. With this patch, '(ref-x obj2)' now uses the exact same method as ':reader', and so would give us 4, as desired. --- lisp/emacs-lisp/eieio.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 39a5fd5b19c..8224606ec57 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -213,9 +213,8 @@ defclass ,(internal--format-docstring-line "Retrieve the slot `%S' from an object of class `%S'." sname name) - ;; FIXME: Why is this different from the :reader case? - (if (slot-boundp this ',sname) (eieio-oref this ',sname))) - accessors) + (slot-value this ',sname)) + accessors) (when (and eieio-backward-compatibility (eq alloc :class)) ;; FIXME: How could I declare this *method* as obsolete. (push `(cl-defmethod ,acces ((this (subclass ,name))) -- 2.39.2