Subject: Re: bug#78786: 31.0.50; eieio-core.el requires byte compilation

From: Pip Cet <[email-masked]>
Date: Sat, 05 Jul 2025 18:59:56 +0000

"Stefan Monnier" <[email-masked]> writes:

>> I propose moving to cl--class-* accessors where we can, and calling
>> eieio--class-slot-name-index and eieio--class-initarg-to-attribute only
>> on known/checked eieio--class objects.
>
> Yes, calling `eieio--class-slot-name-index` on non-EIEIO classes is
> a bug, we should fix the code to do it only when it is an EIEIO class.

So this?

diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index 72640e88301..6d9a0199ea6 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -740,7 +740,8 @@ eieio-oref
       (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 @@ eieio-oref-default
     (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 @@ eieio-oset
       (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 (eieie--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 @@ eieio-oset-default
     (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..f00914d9fe9 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
@@ -1047,7 +1047,8 @@ eieio-test-defstruct-slot-value
                 (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)
+    (should-error (eieio-oref x 'd) :type 'invalid-slot-name)))
 
 (defclass foo-bug-66938 (eieio-instance-inheritor)
   ((x :initarg :x

The new test didn't actually fail before, but I figured it might catch
some future bug.

Pip