diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-10-31 10:57:44 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-10-31 10:58:43 -0400 |
commit | d553e603f405acb06ad9ea233543ebe6ce319210 (patch) | |
tree | 679f835c197742e32b222ea59af69d55b20673cb /test/lisp/emacs-lisp | |
parent | c062c9d4db0ed5d9a1bc45696ae660234d37d1cf (diff) | |
download | emacs-d553e603f405acb06ad9ea233543ebe6ce319210.tar.gz emacs-d553e603f405acb06ad9ea233543ebe6ce319210.tar.bz2 emacs-d553e603f405acb06ad9ea233543ebe6ce319210.zip |
eieio-core.el: Make slot-value work on defstructs
Adjust the values in EIEIO's index-tables so they are compatible with those
of defstructs.
* lisp/emacs-lisp/eieio-core.el (eieio--slot-name-index): Don't add the
`eieio--object-num-slots` offset.
(eieio-defclass-internal): Add the `eieio--object-num-slots` offset
here instead.
(eieio-oref): Allow its use on `cl-structure-object`.
* lisp/emacs-lisp/eieio.el (eieio-pcase-slot-index-from-index-table):
Don't need to add the `eieio--object-num-slots` offset.
* doc/misc/eieio.texi (Accessing Slots, Accessing Slots):
Mention the use on structs.
* test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
(eieio-test-defstruct-slot-value): New test.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r-- | test/lisp/emacs-lisp/eieio-tests/eieio-tests.el | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el index 9eb7fb02230..ba2e5f7be4a 100644 --- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el +++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el @@ -969,6 +969,18 @@ Subclasses to override slot attributes.") (should (eieio-instance-inheritor-slot-boundp C :b)) (should-not (eieio-instance-inheritor-slot-boundp C :c)))) +;;;; Interaction with defstruct + +(cl-defstruct eieio-test--struct a b c) + +(ert-deftest eieio-test-defstruct-slot-value () + (let ((x (make-eieio-test--struct :a 'A :b 'B :c 'C))) + (should (eq (eieio-test--struct-a x) + (slot-value x 'a))) + (should (eq (eieio-test--struct-b x) + (slot-value x 'b))) + (should (eq (eieio-test--struct-c x) + (slot-value x 'c))))) (provide 'eieio-tests) |