From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader when reading a slot's value Date: Sat, 25 Nov 2023 11:28:17 +0200 Message-ID: <837cm6dvwu.fsf@gnu.org> References: <83leb4wpy4.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35676"; mail-complaints-to="usenet@ciao.gmane.io" Cc: brandon.irizarry@gmail.com, 66938@debbugs.gnu.org To: monnier@iro.umontreal.ca Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 25 10:29:04 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r6oyF-00094E-S7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Nov 2023 10:29:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6oyA-0005mZ-AK; Sat, 25 Nov 2023 04:28:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6oy9-0005mC-0O for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 04:28:57 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r6oy8-0007eD-OZ for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 04:28:56 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6oyD-00014P-ME for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 04:29:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Nov 2023 09:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66938 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66938-submit@debbugs.gnu.org id=B66938.17009045124073 (code B ref 66938); Sat, 25 Nov 2023 09:29:01 +0000 Original-Received: (at 66938) by debbugs.gnu.org; 25 Nov 2023 09:28:32 +0000 Original-Received: from localhost ([127.0.0.1]:37814 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6oxk-00013d-2o for submit@debbugs.gnu.org; Sat, 25 Nov 2023 04:28:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6oxi-00013Q-4H for 66938@debbugs.gnu.org; Sat, 25 Nov 2023 04:28:30 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6oxX-0007ck-8G; Sat, 25 Nov 2023 04:28:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=WJFGE7ZHws0RDGUJ0AiBD7iixaZKA8xEVzrUMQ5AI18=; b=ZpS+YRbu+Dc2 FIy2FaNxOf9JEodXbFeDf0Q2XujgeFAIt2cMhn1xpftlAr24OEb9gU2hBUx3gqVB9F66hR8CZtylz oiwIWIHxzrUV9Z6JyJd8ai34uz8A4FAjgub/c1BA963o0OP4ZD3dLyrYSGmmYaWP1lQ04GAAzW/Uu jwlNh5AkOpMa43hJTK1KojjdhnJIv29pbxlTdOmkhY6uaEhJ8g6c4xereNwyGnzk9h/KjkmIBcPtN vrIhdH6fEm4VevsvaqySPgbFkvrm81XoQB2qEyAblvq1lN4gfYFsbEYJUSoj+zAeKlZ/ZYxWOWpQG jUCvKtzZ8yW/3n0y6OHA4g==; In-Reply-To: <83leb4wpy4.fsf@gnu.org> (message from Eli Zaretskii on Sat, 11 Nov 2023 12:21:23 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274934 Archived-At: Ping! Stefan, could you please look into this? > Cc: 66938@debbugs.gnu.org > Date: Sat, 11 Nov 2023 12:21:23 +0200 > From: Eli Zaretskii > > Stefan, any comments? > > > From: Brandon Irizarry > > Date: Sat, 4 Nov 2023 18:03:06 -0400 > > > > 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. > > > > However, neither 'oref' nor ':reader' methods share this problem. > > > > The included patch duplicates the code for the reader method defined for > > the ':reader' case. In particular, it removes the 'slot-unboundp' check, which appeared > > to be the real culprit here. I've also deleted the FIXME comment which asked, "Why is this > > different from the :reader case?" since it no longer differs from it. > > > > There is some more context provided (along with an example) in the > > commit message included in the patch, in case it helps. > > > > I know this isn't earth-shattering, but I couldn't help but notice the issue; > > and, at least to me, it seemed like incorrect behavior. (Otherwise, in order to > > obtain the delegation behavior for a given slot, I'd be forced to define > > ':reader' and ':writer' separately, which feels rather verbose, given we have ':accessor' > > for this exact purpose.) > > > > - Brandon > > > > > > 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 > > > > > >