aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2021-12-04 13:47:19 -0500
committerStefan Monnier2021-12-04 13:47:35 -0500
commitde727b5886fb4a81df2dc17d9d094e915c1e9fb4 (patch)
treec7e1f3ae109eb8cc6c11abf9391b25bf8d15b8cf /test
parent63be97fb050545cc33ae5d857188ad45fbe27715 (diff)
downloademacs-de727b5886fb4a81df2dc17d9d094e915c1e9fb4.tar.gz
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')
-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.")
971 971
972;;;; Interaction with defstruct 972;;;; Interaction with defstruct
973 973
974(cl-defstruct eieio-test--struct a b c) 974(cl-defstruct eieio-test--struct a b (c nil :read-only t))
975 975
976(ert-deftest eieio-test-defstruct-slot-value () 976(ert-deftest eieio-test-defstruct-slot-value ()
977 (let ((x (make-eieio-test--struct :a 'A :b 'B :c 'C))) 977 (let ((x (make-eieio-test--struct :a 'A :b 'B :c 'C)))
@@ -980,7 +980,10 @@ Subclasses to override slot attributes.")
980 (should (eq (eieio-test--struct-b x) 980 (should (eq (eieio-test--struct-b x)
981 (slot-value x 'b))) 981 (slot-value x 'b)))
982 (should (eq (eieio-test--struct-c x) 982 (should (eq (eieio-test--struct-c x)
983 (slot-value x 'c))))) 983 (slot-value x 'c)))
984 (setf (slot-value x 'a) 1)
985 (should (eq (eieio-test--struct-a x) 1))
986 (should-error (setf (slot-value x 'c) 3) :type 'eieio-read-only)))
984 987
985(provide 'eieio-tests) 988(provide 'eieio-tests)
986 989