>From 595083dac6dd0fe3446e182c710fbb2a5a648994 Mon Sep 17 00:00:00 2001 From: akater Date: Wed, 30 Jun 2021 11:43:23 +0000 Subject: [PATCH] lisp/emacs-lisp/eieio.el (initialize-instance): Fix initform: Do not evaluate initform of a slot when initarg for the slot is provided. According to the following secitons of CLHS: - Object Creation and Initialization - Initialization Arguments - Defaulting of Initialization Arguments - Rules for Initialization Arguments --- lisp/emacs-lisp/eieio.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 1c8c372aae..758bddd592 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -740,7 +740,7 @@ defclass eieio-default-superclass nil "Construct the new object THIS based on SLOTS.") (cl-defmethod initialize-instance ((this eieio-default-superclass) - &optional slots) + &optional slots) "Construct the new object THIS based on SLOTS. SLOTS is a tagged list where odd numbered elements are tags, and even numbered elements are the values to store in the tagged slot. @@ -756,13 +756,15 @@ defclass eieio-default-superclass nil (dotimes (i (length slots)) ;; For each slot, see if we need to evaluate it. (let* ((slot (aref slots i)) + (slot-name (eieio-slot-descriptor-name slot)) (initform (cl--slot-descriptor-initform slot))) ;; Those slots whose initform is constant already have the right ;; value set in the default-object. - (unless (macroexp-const-p initform) + (unless (or (rassq slot-name + (eieio--class-initarg-tuples this-class)) + (macroexp-const-p initform)) ;; FIXME: We should be able to just do (aset this (+ i ) dflt)! - (eieio-oset this (cl--slot-descriptor-name slot) - (eval initform t)))))) + (eieio-oset this slot-name (eval initform t)))))) ;; Shared initialize will parse our slots for us. (shared-initialize this slots)) -- 2.31.1