From afda2ad5daf854b3002c24c677f805631eba2486 Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Wed, 9 Jul 2025 15:16:07 +0000 Subject: [PATCH] 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. (cherry picked from commit 6a5d9cb07d6ef8c8913acb304eea365c85d82449) --- lisp/emacs-lisp/eieio-core.el | 16 ++++++++++------ test/lisp/emacs-lisp/eieio-tests/eieio-tests.el | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index 0beca666c48..a88473ee792 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el @@ -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) diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el index fced6bc3df2..b60db80ad56 100644 --- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el +++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el @@ -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 -- 2.39.5