summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorEric Abrahamsen <eric@ericabrahamsen.net>2017-09-30 10:57:52 -0700
committerEric Abrahamsen <eric@ericabrahamsen.net>2017-09-30 16:28:00 -0700
commitc59ddb212055609ec0c402708a2514ee6a30e836 (patch)
treef947e55c19617feba81f1115e926bcf6eaad7df7 /lisp/emacs-lisp
parent8b2ab5014b2c1641bb62efa63b9ee54b4c056b5a (diff)
downloademacs-c59ddb212055609ec0c402708a2514ee6a30e836.tar.gz
emacs-c59ddb212055609ec0c402708a2514ee6a30e836.tar.bz2
emacs-c59ddb212055609ec0c402708a2514ee6a30e836.zip
Fix slot typecheck in eieio-persistent
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-slot-type-is-class-p): An `or' form can specify multiple potential classes (or null) as valid types for a slot, but previously only the final element of the `or' was actually checked. Now returns all valid classes in the `or' form. (eieio-persistent-validate/fix-slot-value): Check if proposed value matches any of the valid classes. * test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el (eieio-test-multiple-class-slot): Test this behavior.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/eieio-base.el29
1 files changed, 14 insertions, 15 deletions
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 6b39b4f2622..e3501be6c1d 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -31,6 +31,7 @@
;;; Code:
(require 'eieio)
+(require 'seq)
(eval-when-compile (require 'cl-lib))
;;; eieio-instance-inheritor
@@ -308,14 +309,6 @@ Second, any text properties will be stripped from strings."
(= (length proposed-value) 1))
nil)
- ;; We have a slot with a single object that can be
- ;; saved here. Recurse and evaluate that
- ;; sub-object.
- ((and classtype (class-p classtype)
- (child-of-class-p (car proposed-value) classtype))
- (eieio-persistent-convert-list-to-object
- proposed-value))
-
;; List of object constructors.
((and (eq (car proposed-value) 'list)
;; 2nd item is a list.
@@ -346,6 +339,16 @@ Second, any text properties will be stripped from strings."
objlist))
;; return the list of objects ... reversed.
(nreverse objlist)))
+ ;; We have a slot with a single object that can be
+ ;; saved here. Recurse and evaluate that
+ ;; sub-object.
+ ((and classtype
+ (seq-some
+ (lambda (elt)
+ (child-of-class-p (car proposed-value) elt))
+ classtype))
+ (eieio-persistent-convert-list-to-object
+ proposed-value))
(t
proposed-value))))
@@ -402,13 +405,9 @@ If no class is referenced there, then return nil."
type))
((eq (car-safe type) 'or)
- ;; If type is a list, and is an or, it is possibly something
- ;; like (or null myclass), so check for that.
- (let ((ans nil))
- (dolist (subtype (cdr type))
- (setq ans (eieio-persistent-slot-type-is-class-p
- subtype)))
- ans))
+ ;; If type is a list, and is an `or', return all valid class
+ ;; types within the `or' statement.
+ (seq-filter #'eieio-persistent-slot-type-is-class-p (cdr type)))
(t
;; No match, not a class.