summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2021-12-04 13:47:19 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2021-12-04 13:47:35 -0500
commitde727b5886fb4a81df2dc17d9d094e915c1e9fb4 (patch)
treec7e1f3ae109eb8cc6c11abf9391b25bf8d15b8cf /test/lisp/emacs-lisp
parent63be97fb050545cc33ae5d857188ad45fbe27715 (diff)
downloademacs-de727b5886fb4a81df2dc17d9d094e915c1e9fb4.tar.gz
emacs-de727b5886fb4a81df2dc17d9d094e915c1e9fb4.tar.bz2
emacs-de727b5886fb4a81df2dc17d9d094e915c1e9fb4.zip
eieio-core.el: Allow assignment to cl-structs through `slot-value`
* lisp/emacs-lisp/eieio-core.el (eieio--validate-slot-value): Obey the `:read-only` property of the slot. (eieio-oset): Allow use on cl-structs as well. (eieio-read-only): New error. * test/lisp/emacs-lisp/eieio-tests/eieio-tests.el (eieio-test--struct): Make the last field read-only. (eieio-test-defstruct-slot-value): Test that cl-struct slots can be assigned via `slot-value`.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r--test/lisp/emacs-lisp/eieio-tests/eieio-tests.el7
1 files changed, 5 insertions, 2 deletions
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
index dfdfb63b584..6f6a1f4f19a 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
@@ -971,7 +971,7 @@ Subclasses to override slot attributes.")
;;;; Interaction with defstruct
-(cl-defstruct eieio-test--struct a b c)
+(cl-defstruct eieio-test--struct a b (c nil :read-only t))
(ert-deftest eieio-test-defstruct-slot-value ()
(let ((x (make-eieio-test--struct :a 'A :b 'B :c 'C)))
@@ -980,7 +980,10 @@ Subclasses to override slot attributes.")
(should (eq (eieio-test--struct-b x)
(slot-value x 'b)))
(should (eq (eieio-test--struct-c x)
- (slot-value x 'c)))))
+ (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)))
(provide 'eieio-tests)