]> git.eshelyaron.com Git - emacs.git/commitdiff
cl-defstruct: Fix debug spec and check of slot options
authorJohan Bockgård <bojohan@gnu.org>
Tue, 18 Oct 2016 20:28:17 +0000 (22:28 +0200)
committerJohan Bockgård <bojohan@gnu.org>
Tue, 18 Oct 2016 22:32:12 +0000 (00:32 +0200)
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Improve checking of slot
option syntax.  Fix debug spec.  (Bug#24700)

lisp/emacs-lisp/cl-macs.el

index f5b7b82643151413a7d8ff5faa958d0f0510b588..0096e0aab3e9c440c414055ebb5a4d675e609cb0 100644 (file)
@@ -2590,8 +2590,7 @@ non-nil value, that slot cannot be set via `setf'.
                              [":initial-offset" natnump])])]
              [&optional stringp]
              ;; All the above is for the following def-form.
-             &rest &or symbolp (symbolp def-form
-                                        &optional ":read-only" sexp))))
+             &rest &or symbolp (symbolp &optional def-form &rest sexp))))
   (let* ((name (if (consp struct) (car struct) struct))
         (opts (cdr-safe struct))
         (slots nil)
@@ -2655,7 +2654,7 @@ non-nil value, that slot cannot be set via `setf'.
               (setq descs (nconc (make-list (car args) '(cl-skip-slot))
                                  descs)))
              (t
-              (error "Slot option %s unrecognized" opt)))))
+              (error "Structure option %s unrecognized" opt)))))
     (unless (or include-name type)
       (setq include-name cl--struct-default-parent))
     (when include-name (setq include (cl--struct-get-class include-name)))
@@ -2711,7 +2710,7 @@ non-nil value, that slot cannot be set via `setf'.
     (let ((pos 0) (descp descs))
       (while descp
        (let* ((desc (pop descp))
-              (slot (car desc)))
+              (slot (pop desc)))
          (if (memq slot '(cl-tag-slot cl-skip-slot))
              (progn
                (push nil slots)
@@ -2721,7 +2720,7 @@ non-nil value, that slot cannot be set via `setf'.
                (error "Duplicate slots named %s in %s" slot name))
            (let ((accessor (intern (format "%s%s" conc-name slot))))
              (push slot slots)
-             (push (nth 1 desc) defaults)
+             (push (pop desc) defaults)
              ;; The arg "cl-x" is referenced by name in eg pred-form
              ;; and pred-check, so changing it is not straightforward.
              (push `(cl-defsubst ,accessor (cl-x)
@@ -2736,7 +2735,9 @@ non-nil value, that slot cannot be set via `setf'.
                           (if (= pos 0) '(car cl-x)
                             `(nth ,pos cl-x))))
                     forms)
-              (if (cadr (memq :read-only (cddr desc)))
+              (when (cl-oddp (length desc))
+                (error "Invalid options for slot %s in %s" slot name))
+              (if (plist-get desc ':read-only)
                   (push `(gv-define-expander ,accessor
                            (lambda (_cl-do _cl-x)
                              (error "%s is a read-only slot" ',accessor)))