From e28c99082ac03b06600b8b943704e0786c8887f9 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 3 Jan 2017 16:07:44 -0500 Subject: [PATCH] (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. --- lisp/emacs-lisp/cl-macs.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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) -- 2.39.5