diff options
author | Andrea Corallo <acorallo@gnu.org> | 2024-07-24 14:08:31 +0200 |
---|---|---|
committer | Andrea Corallo <acorallo@gnu.org> | 2024-07-24 19:20:11 +0200 |
commit | baf9f1210a3e44aa19d9ac90e5a4faca214127a7 (patch) | |
tree | f503b8bcd822cc3b472ecd445930bcbdb28731d8 /lisp/emacs-lisp/byte-run.el | |
parent | df25bd12fc323b2e6ac76f05882d3902ce92b4cf (diff) | |
download | emacs-baf9f1210a3e44aa19d9ac90e5a4faca214127a7.tar.gz emacs-baf9f1210a3e44aa19d9ac90e5a4faca214127a7.tar.bz2 emacs-baf9f1210a3e44aa19d9ac90e5a4faca214127a7.zip |
Add some basic checking for function type declarations
* lisp/emacs-lisp/byte-run.el (byte-run--anonymize-arg-list): New function.
(byte-run--set-function-type): Add some basic checking for
the function type being declared.
Diffstat (limited to 'lisp/emacs-lisp/byte-run.el')
-rw-r--r-- | lisp/emacs-lisp/byte-run.el | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index 75cfc7b32d3..f1486f70634 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -222,12 +222,27 @@ So far, FUNCTION can only be a symbol, not a lambda expression." (cadr elem))) val))))) +(defalias 'byte-run--anonymize-arg-list + #'(lambda (arg-list) + (mapcar (lambda (x) + (if (memq x '(&optional &rest)) + x + t)) + arg-list))) + (defalias 'byte-run--set-function-type - #'(lambda (f _args val &optional f2) + #'(lambda (f args val &optional f2) (when (and f2 (not (eq f2 f))) (error "`%s' does not match top level function `%s' inside function type \ declaration" f2 f)) + (unless (and (length= val 3) + (eq (car val) 'function) + (listp (car (cdr val)))) + (error "Type `%s' is not valid a function type" val)) + (unless (equal (byte-run--anonymize-arg-list args) + (byte-run--anonymize-arg-list (car (cdr val)))) + (error "Type `%s' incompatible with function arguments `%s'" val args)) (list 'function-put (list 'quote f) ''function-type (list 'quote val)))) |