emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 484b0979099: (cl-defstruct): Improve handling of unknown options


From: Stefan Monnier
Subject: master 484b0979099: (cl-defstruct): Improve handling of unknown options
Date: Tue, 16 Apr 2024 21:17:55 -0400 (EDT)

branch: master
commit 484b0979099d91e286c248e32b2f693111fac2ad
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (cl-defstruct): Improve handling of unknown options
    
    Until now `cl-defstruct` signaled an error when encountering an
    unknown option.  It's easy to code and it does the job, but it
    doesn't give good location info in the compiler's output,
    and it makes it more painful to use not-yet-supported options.
    So just signal a warning instead.
    
    * lisp/emacs-lisp/cl-macs.el (cl-defstruct): Warn about unknown
    options, instead of signaling an error.
---
 lisp/emacs-lisp/cl-macs.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 1350e474d6a..2e501005bf7 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -3010,6 +3010,7 @@ To see the documentation for a defined struct type, use
              ;; All the above is for the following def-form.
              &rest &or symbolp (symbolp &optional def-form &rest sexp))))
   (let* ((name (if (consp struct) (car struct) struct))
+        (warning nil)
         (opts (cdr-safe struct))
         (slots nil)
         (defaults nil)
@@ -3094,7 +3095,10 @@ To see the documentation for a defined struct type, use
               (setq descs (nconc (make-list (car args) '(cl-skip-slot))
                                  descs)))
              (t
-              (error "Structure option %s unrecognized" opt)))))
+              (setq warning
+                    (macroexp-warn-and-return
+                     (format "Structure option %S unrecognized" opt)
+                     warning nil nil (list opt struct)))))))
     (unless (or include-name type
                 ;; Don't create a bogus parent to `cl-structure-object'
                 ;; while compiling the (cl-defstruct cl-structure-object ..)
@@ -3333,6 +3337,7 @@ To see the documentation for a defined struct type, use
          (cl-struct-define ',name ,docstring ',include-name
                            ',(or type 'record) ,(eq named t) ',descs
                            ',tag-symbol ',tag ',print-auto))
+       ,warning
        ',name)))
 
 ;;; Add cl-struct support to pcase



reply via email to

[Prev in Thread] Current Thread [Next in Thread]