Subject: Re: bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader when reading a slot's value

From: Brandon Irizarry <[email-masked]>
Date: Sat, 25 Nov 2023 22:21:21 -0500

Done. The patch is included with this email.

- Brandon

On Sat, Nov 25, 2023 at 9:57 AM Stefan Monnier <[email-masked]>
wrote:

> [ Sorry for the delay, and thanks Eli for re-pinging me.  ]
>
> > I've included a suggested patch for 'eieio.el', which slightly
> > modifies the behavior of EIEIO's 'defclass'. When playing around with
> > 'eieio-instance-inheritor' as a base class, I noticed that calls to
> > the accessor (when used as a getter) weren't delegating to the parent
> > instance (as defined when calling 'clone'). That is, an object clone that
> > doesn't set
> > its fields directly will report 'nil' when the accessor method is used
> as a
> > getter for some slot.
>
> The patch looks great and confirms my FIXME.
>
> Could you turn the example in the commit message into a test in
> test/lisp/emacs-lisp/eieio-tests/eieio-tests.el?
>
>
>         Stefan
>
>
From 353dcb3333300a6f86f7bfa210d704876ec7b701 Mon Sep 17 00:00:00 2001
From: "Brandon C. Irizarry" <[email-masked]>
Date: Sat, 25 Nov 2023 22:09:00 -0500
Subject: [PATCH] Bug 66938: add example used in patch commit message to
 eieio-tests.el

This is in response to a request made by Stefan Monnier on
bug-gnu-emacs.
---
 .../emacs-lisp/eieio-tests/eieio-tests.el     | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
index c9993341f98..a0507afe833 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
@@ -1046,6 +1046,27 @@ eieio-test-defstruct-slot-value
     (should (eq (eieio-test--struct-a x) 1))
     (should-error (setf (slot-value x 'c) 3) :type 'eieio-read-only)))
 
+(defclass foo-bug-66938 (eieio-instance-inheritor)
+  ((x :initarg :x
+      :accessor ref-x
+      :reader get-x))
+  "A class to test that delegation occurs under certain
+circumstances when using an accessor function, as it would when
+using the reader function.")
+
+(ert-deftest eieio-test-use-accessor-function-with-cloned-object ()
+  "The class FOO-BUG-66938 is a subclass of
+`eieio-instance-inheritor'. Therefore, given an instance OBJ1 of
+FOO-BUG-66938, and a clone (OBJ2), OBJ2 should delegate to OBJ1
+when accessing an unbound slot.
+
+In particular, its behavior should be identical to that of the
+reader function, when reading a slot."
+  (let* ((obj1 (foo-bug-66938 :x 4))
+         (obj2 (clone obj1)))
+    (should (eql (ref-x obj2) 4))
+    (should (eql (get-x obj2) (ref-x obj2)))))
+
 (provide 'eieio-tests)
 
 ;;; eieio-tests.el ends here
-- 
2.39.2