Skip to content

Commit 37436fe

Browse files
committed
Fix cloning of eieio-named objects (Bug#22840)
* lisp/emacs-lisp/eieio-base.el (clone): Correctly set the name of the cloned objects from eieio-named instances.
1 parent fb65a36 commit 37436fe

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lisp/emacs-lisp/eieio-base.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,18 @@ instance."
510510
All slots are unbound, except those initialized with PARAMS."
511511
(let* ((newname (and (stringp (car params)) (pop params)))
512512
(nobj (apply #'cl-call-next-method obj params))
513-
(nm (slot-value obj 'object-name)))
514-
(eieio-oset obj 'object-name
513+
(nm (slot-value nobj 'object-name)))
514+
(eieio-oset nobj 'object-name
515515
(or newname
516-
(save-match-data
517-
(if (and nm (string-match "-\\([0-9]+\\)" nm))
518-
(let ((num (1+ (string-to-number
519-
(match-string 1 nm)))))
520-
(concat (substring nm 0 (match-beginning 0))
521-
"-" (int-to-string num)))
522-
(concat nm "-1")))))
516+
(if (equal nm (slot-value obj 'object-name))
517+
(save-match-data
518+
(if (and nm (string-match "-\\([0-9]+\\)" nm))
519+
(let ((num (1+ (string-to-number
520+
(match-string 1 nm)))))
521+
(concat (substring nm 0 (match-beginning 0))
522+
"-" (int-to-string num)))
523+
(concat nm "-1")))
524+
nm)))
523525
nobj))
524526

525527
(cl-defmethod make-instance ((class (subclass eieio-named)) &rest args)

test/lisp/emacs-lisp/eieio-tests/eieio-tests.el

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,7 @@ Subclasses to override slot attributes.")
862862
(should (oref obj1 a-slot))))
863863

864864
(defclass NAMED (eieio-named)
865-
((some-slot :initform nil)
866-
)
865+
((some-slot :initform nil))
867866
"A class inheriting from eieio-named.")
868867

869868
(ert-deftest eieio-test-35-named-object ()
@@ -902,6 +901,18 @@ Subclasses to override slot attributes.")
902901
(should
903902
(fboundp 'eieio--defalias)))
904903

904+
(ert-deftest eieio-test-38-clone-named-object ()
905+
(let* ((A (NAMED :object-name "aa"))
906+
(B (clone A :object-name "bb"))
907+
(C (clone A "cc"))
908+
(D (clone A))
909+
(E (clone D)))
910+
(should (string= "aa" (oref A object-name)))
911+
(should (string= "bb" (oref B object-name)))
912+
(should (string= "cc" (oref C object-name)))
913+
(should (string= "aa-1" (oref D object-name)))
914+
(should (string= "aa-2" (oref E object-name)))))
915+
905916

906917
(provide 'eieio-tests)
907918

0 commit comments

Comments
 (0)