(defclass): Don't duplicate the compiler macro

* lisp/emacs-lisp/eieio.el (eieio--constructor-macro): New function.
(defclass): Use it.
This commit is contained in:
Stefan Monnier 2025-04-04 16:48:57 -04:00
parent fce3f0ad4a
commit 21920da6c7

View file

@ -289,20 +289,22 @@ and reference them using the function `class-option'."
`(defun ,name (&rest slots)
,(internal--format-docstring-line
"Create a new object of class type `%S'." name)
(declare (compiler-macro
(lambda (whole)
(if (not (stringp (car slots)))
whole
(macroexp-warn-and-return
(format "Obsolete name arg %S to constructor %S"
(car slots) (car whole))
;; Keep the name arg, for backward compatibility,
;; but hide it so we don't trigger indefinitely.
`(,(car whole) (identity ,(car slots))
,@(cdr slots))
nil nil (car slots))))))
(declare (compiler-macro eieio--constructor-macro))
(apply #'make-instance ',name slots))))))
(defun eieio--constructor-macro (whole &rest slots)
(if (or (null slots) (keywordp (car slots))
;; Detect the second pass!
(eq 'identity (car-safe (car slots))))
whole
(macroexp-warn-and-return
(format "Obsolete name arg %S to constructor %S"
(car slots) (car whole))
;; Keep the name arg, for backward compatibility,
;; but hide it so we don't trigger indefinitely.
`(,(car whole) (identity ,(car slots))
,@(cdr slots))
nil nil (car slots))))
;;; Get/Set slots in an object.
;;