(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.
This commit is contained in:
parent
5c6f1198d4
commit
e28c99082a
1 changed files with 17 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue