bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66938: 30.0.50 [PATCH]: Make EIEIO :accessor behave like :reader whe


From: Stefan Monnier
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
User-agent: Gnus/5.13 (Gnus v5.13)

>> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]