unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: "João Távora" <joaotavora@gmail.com>
Cc: brandon.irizarry@gmail.com, 66938@debbugs.gnu.org,
	66938-done@debbugs.gnu.org
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	[thread overview]
Message-ID: <jwvzfywmuql.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CALDnm51_rmcxZE_YPTUjERCMmoDGJnaDqih0FJJser_WRqZUsA@mail.gmail.com> ("João Távora"'s message of "Wed, 29 Nov 2023 14:36:15 +0000")

>> 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))))))
 






  reply	other threads:[~2023-11-29 15:46 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
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 [this message]
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=jwvzfywmuql.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=66938-done@debbugs.gnu.org \
    --cc=66938@debbugs.gnu.org \
    --cc=brandon.irizarry@gmail.com \
    --cc=joaotavora@gmail.com \
    --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).