emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6c47931a1ad: Make EIEIO ':accessor' behave like ':reader' when re


From: Stefan Monnier
Subject: master 6c47931a1ad: Make EIEIO ':accessor' behave like ':reader' when reading (bug#66938)
Date: Sun, 26 Nov 2023 08:51:54 -0500 (EST)

branch: master
commit 6c47931a1ad4de4af3f147b9604169c2441100fe
Author: Brandon <brandon.irizarry@gmail.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Make EIEIO ':accessor' behave like ':reader' when reading (bug#66938)
    
    Clones of instances of subclasses of 'eieio-instance-inheritor' didn't
    delegate to their ':parent-instance' field when reading object fields
    using ':accessor'.
    
    * lisp/emacs-lisp/eieio.el (defclass): Remove 'slot-boundp' check for
    :accessor's getter
    * test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
    (eieio-test-use-accessor-function-with-cloned-object): New test.
    
    Copyright-paperwork-exempt: yes
---
 lisp/emacs-lisp/eieio.el                        |  5 ++---
 test/lisp/emacs-lisp/eieio-tests/eieio-tests.el | 21 +++++++++++++++++++++
 2 files changed, 23 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 @@ and reference them using the function `class-option'."
                    ,(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)))
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 @@ Subclasses to override slot attributes."))
     (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]