From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader when reading a slot's value Date: Wed, 29 Nov 2023 10:46:52 -0500 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23808"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: brandon.irizarry@gmail.com, 66938@debbugs.gnu.org, 66938-done@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 29 16:48:24 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 1r8MnY-0005yA-Lo for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Nov 2023 16:48:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8MnM-0005zF-7Y; Wed, 29 Nov 2023 10:48:13 -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 1r8Mn5-0005qv-8c for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 10:47:58 -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 1r8Mn5-0001Bd-0p for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 10:47:55 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8MnC-0005Lo-HJ for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 10:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Nov 2023 15:48: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.170127284320414 (code B ref 66938); Wed, 29 Nov 2023 15:48:02 +0000 Original-Received: (at 66938) by debbugs.gnu.org; 29 Nov 2023 15:47:23 +0000 Original-Received: from localhost ([127.0.0.1]:50770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8MmY-0005J7-UN for submit@debbugs.gnu.org; Wed, 29 Nov 2023 10:47:23 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:2718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8MmW-0005Im-Cq; Wed, 29 Nov 2023 10:47:21 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 011E34413ED; Wed, 29 Nov 2023 10:47:07 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1701272825; bh=BD97CcHs/D0C5noBCN+uJIEhmIO4mXqF150e7visDUI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=fPFh+PmbDJsf9ZzaCC2uXnl1N9DuWqqmmlbhUfZOiGiRqgEaLyGZrpXcYh7kweLMQ Yj6lk9g5ieB26foWstkJzmtxyGvnncILB9aNrdOUGQwI7qK0IDCKOoGaZF4OjYegMp o663ymw8DufB9T15dFhjQJYG15T+4WFXmPTZ8Rxou2fLP82lpdAI9JY9U+oC3i6AUK IL9OZ/ofZMQeOvUsgLfMDq11AEyO13dAhA6BghdwygYxxqr4RxqpHA2bHm4r8crArX pTP+nf5TqQ8duq0n0VRIA2aq9wVpRFu4ZhOP9M/At+cO83N2ASifLn9ydHDcgwhuRr VHKtuSyFs+6Gg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E4A624413CA; Wed, 29 Nov 2023 10:47:05 -0500 (EST) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D2A541201AA; Wed, 29 Nov 2023 10:47:05 -0500 (EST) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Wed, 29 Nov 2023 14:36:15 +0000") 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:275244 Archived-At: >> I think this works nowadays (the expression is not evaluated in the >> right context (it's evaluated in the empty context), but AFAICT it's >> evaluated at the right time): > No, I think there's something off. In CLOS: [...] > *** Welcome to IELM *** Type (describe-mode) or press C-h m for help. > ELISP> (defclass foo () ((bar :initarg :bar :initform (error "BAR is > required!")))) > *** Eval error *** BAR is required! > ELISP> Duh! Still victim from the original EIEIO design where the `:initform`s were executed at `defclass` time and then stored in a kind of "prototype" object (presumably to speed up the creation of objects). I pushed the patch below to fix this problem. I can't believe this has lingered since my Emacs-25 "rework" where I went through the trouble to better align the semantics with that of CLOS. Stefan diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index a394156c93a..37c5ebdb6da 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el @@ -951,7 +951,10 @@ eieio-set-defaults (let ((slots (eieio--class-slots (eieio--object-class obj)))) (dotimes (i (length slots)) (let* ((name (cl--slot-descriptor-name (aref slots i))) - (df (eieio-oref-default obj name))) + ;; If the `:initform` signals an error, just skip it, + ;; since the error is intended to be signal'ed from + ;; `initialize-instance` rather than at the time of `defclass`. + (df (ignore-errors (eieio-oref-default obj name)))) (if (or df set-all) (eieio-oset obj name df))))))