]> git.eshelyaron.com Git - emacs.git/commitdiff
(cl-defstruct): Improve error message for slots w/o value (bug#25312)
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Jan 2017 21:07:44 +0000 (16:07 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Jan 2017 21:07:44 +0000 (16:07 -0500)
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Don't signal an error but
emit a warning for those coders who forgot to put a default value in
their slot.

lisp/emacs-lisp/cl-macs.el

index 945da1fb39fc6f7772e029addf3c91f7aac1f234..40342f3fe48d60fff1b86b8e66a805f32119f8a0 100644 (file)
@@ -2745,7 +2745,23 @@ non-nil value, that slot cannot be set via `setf'.
                             `(nth ,pos cl-x))))
                     forms)
               (when (cl-oddp (length desc))
-                (error "Invalid options for slot %s in %s" slot name))
+                (push
+                 (macroexp--warn-and-return
+                  (format "Missing value for option `%S' of slot `%s' in struct %s!"
+                          (car (last desc)) slot name)
+                  'nil)
+                 forms)
+                (when (and (keywordp (car defaults))
+                           (not (keywordp (car desc))))
+                  (let ((kw (car defaults)))
+                    (push
+                     (macroexp--warn-and-return
+                      (format "  I'll take `%s' to be an option rather than a default value."
+                              kw)
+                      'nil)
+                     forms)
+                    (push kw desc)
+                    (setcar defaults nil))))
               (if (plist-get desc ':read-only)
                   (push `(gv-define-expander ,accessor
                            (lambda (_cl-do _cl-x)