diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2017-01-03 16:07:44 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2017-01-03 16:07:44 -0500 |
commit | e28c99082ac03b06600b8b943704e0786c8887f9 (patch) | |
tree | ec602acb0196bb05a67c9fdd7ef89f06225b6e76 | |
parent | 5c6f1198d40b404573e5dfd2b0f1e5c73f71209b (diff) | |
download | emacs-e28c99082ac03b06600b8b943704e0786c8887f9.tar.gz |
(cl-defstruct): Improve error message for slots w/o value (bug#25312)
* 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.
-rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 945da1fb39f..40342f3fe48 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -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) |