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, 11 Nov 2023 12:21:23 +0200 Message-ID: <83leb4wpy4.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28224"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66938@debbugs.gnu.org To: Brandon Irizarry , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 11 11:22:35 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 1r1l8M-00073t-10 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Nov 2023 11:22:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1l8B-00058p-GE; Sat, 11 Nov 2023 05:22:23 -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 1r1l8A-00058O-1z for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 05:22:22 -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 1r1l89-0003VN-QQ for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 05:22:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r1l8o-0004KT-1O for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 05:23:02 -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, 11 Nov 2023 10:23:02 +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.169969813216554 (code B ref 66938); Sat, 11 Nov 2023 10:23:02 +0000 Original-Received: (at 66938) by debbugs.gnu.org; 11 Nov 2023 10:22:12 +0000 Original-Received: from localhost ([127.0.0.1]:52101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1l7z-0004Iw-Th for submit@debbugs.gnu.org; Sat, 11 Nov 2023 05:22:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1l7y-0004Ih-M8 for 66938@debbugs.gnu.org; Sat, 11 Nov 2023 05:22:11 -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 1r1l7F-0003Pl-3s; Sat, 11 Nov 2023 05:21:25 -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=rIJ4JjfedWqoCCGcHPzhg3KkaY5bVVBo4nbG85XOPtU=; b=gZKEMqjbE6HF oEF/sFf+KQV6roBiAclP5wgAr+1GDBqHVk8GQqn90cp5+kONN9eQf4koHt5Vxch66I9K5+Py5DdcP /gzL5gvcyEs9Uov5XOyxKQ4RLG4LzC0nQP7AS17dopbg0jyi5oktbQ4GbYCi4peHvBSknlpT2lpm2 2lpNpGg+txeAjRfE+XBzMAHd4EpjeH4/9i3idrTcWnJhQDIi1j0o3JHAMNm+iTlEXIZ4gjsaDb4nw UcM+4o1QYGSCYzrv1tSuGb4Gzn9RdiQ9S4Ly0AeJw1fi+9wlyfTmLI+OdFc6A0GO+S8L7za5cGSFG Fn2t4KSmII9+Y6+ajFELTw==; In-Reply-To: (message from Brandon Irizarry on Sat, 4 Nov 2023 18:03:06 -0400) 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:274151 Archived-At: 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 >