1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-06 03:40:56 -08:00

Call eieio--class-* accessors only on eieio classes (bug#78786)

* lisp/emacs-lisp/eieio-core.el (eieio-oref, eieio-oref-default):
(eieio-oset, eieio-oset-default): Don't look for class slots except in
eieio classes.
* test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
(eieio-test-defstruct-slot-value): New test.
This commit is contained in:
Pip Cet 2025-07-09 15:16:07 +00:00
parent a76506f131
commit 6a5d9cb07d
2 changed files with 13 additions and 7 deletions

View file

@ -740,7 +740,8 @@ Argument FN is the function calling this verifier."
(if (not c)
;; It might be missing because it is a :class allocated slot.
;; Let's check that info out.
(if (setq c (eieio--class-slot-name-index class slot))
(if (and (eieio--class-p class)
(setq c (eieio--class-slot-name-index class slot)))
;; Oref that slot.
(aref (eieio--class-class-allocation-values class) c)
;; The slot-missing method is a cool way of allowing an object author
@ -783,8 +784,9 @@ Fills in CLASS's SLOT with its default value."
(if (not c)
;; It might be missing because it is a :class allocated slot.
;; Let's check that info out.
(if (setq c
(eieio--class-slot-name-index cl slot))
(if (and (eieio--class-p cl)
(setq c
(eieio--class-slot-name-index cl slot)))
;; Oref that slot.
(aref (eieio--class-class-allocation-values cl)
c)
@ -808,8 +810,9 @@ Fills in OBJ's SLOT with VALUE."
(if (not c)
;; It might be missing because it is a :class allocated slot.
;; Let's check that info out.
(if (setq c
(eieio--class-slot-name-index class slot))
(if (and (eieio--class-p class)
(setq c
(eieio--class-slot-name-index class slot)))
;; Oset that slot.
(progn
(eieio--validate-class-slot-value class c value slot)
@ -849,7 +852,8 @@ Fills in the default value in CLASS' in SLOT with VALUE."
(if (not c)
;; It might be missing because it is a :class allocated slot.
;; Let's check that info out.
(if (setq c (eieio--class-slot-name-index class slot))
(if (and (eieio--class-p class)
(setq c (eieio--class-slot-name-index class slot)))
(progn
;; Oref that slot.
(eieio--validate-class-slot-value class c value slot)

View file

@ -1047,7 +1047,9 @@ Subclasses to override slot attributes."))
(slot-value x 'c)))
(setf (slot-value x 'a) 1)
(should (eq (eieio-test--struct-a x) 1))
(should-error (setf (slot-value x 'c) 3) :type 'eieio-read-only)))
(should-error (setf (slot-value x 'c) 3) :type 'eieio-read-only)
(with-no-warnings
(should-error (eieio-oref x 'd)) :type 'invalid-slot-name)))
(defclass foo-bug-66938 (eieio-instance-inheritor)
((x :initarg :x