unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Brandon Irizarry <brandon.irizarry@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 66938@debbugs.gnu.org
Subject: bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader when reading a slot's value
Date: Sat, 25 Nov 2023 22:21:21 -0500	[thread overview]
Message-ID: <CAJm+nuEeZE+zW+nPZhNTCwitJHg_oSk9Xdi3Suk4O5a3SptkCg@mail.gmail.com> (raw)
In-Reply-To: <jwvfs0t28ck.fsf-monnier+emacs@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 915 bytes --]

Done. The patch is included with this email.

- Brandon

On Sat, Nov 25, 2023 at 9:57 AM Stefan Monnier <monnier@iro.umontreal.ca>
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
>
>

[-- Attachment #1.2: Type: text/html, Size: 1354 bytes --]

[-- Attachment #2: 0001-Bug-66938-add-example-used-in-patch-commit-message-t.patch --]
[-- Type: text/x-patch, Size: 1749 bytes --]

From 353dcb3333300a6f86f7bfa210d704876ec7b701 Mon Sep 17 00:00:00 2001
From: "Brandon C. Irizarry" <brandon.irizarry@gmail.com>
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


  reply	other threads:[~2023-11-26  3:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04 22:03 bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader when reading a slot's value Brandon Irizarry
2023-11-11 10:21 ` Eli Zaretskii
2023-11-25  9:28   ` Eli Zaretskii
2023-11-25 14:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-26  3:21   ` Brandon Irizarry [this message]
2023-11-26 13:52     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29  0:29       ` João Távora
2023-11-29 14:01         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 14:36           ` João Távora
2023-11-29 15:46             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 16:09               ` João Távora
2023-11-29 16:36                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29  2:01 ` bug#66938: 30.0.50; Commit 6c47931a1ad4de ("Make EIEIO ':accessor' behave like ':reader' when reading (bug#66938)") breaks Eglot Arsen Arsenović via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 15:01   ` João Távora
2023-11-29 15:25     ` Arsen Arsenović via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 15:43       ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJm+nuEeZE+zW+nPZhNTCwitJHg_oSk9Xdi3Suk4O5a3SptkCg@mail.gmail.com \
    --to=brandon.irizarry@gmail.com \
    --cc=66938@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).