Don't complain on compiler-macro arity mismatch

* lisp/emacs-lisp/macroexp.el (macroexp--compiler-macro):
Don't warn if calling the compiler-macro handler elicits an arity error.

This helps in two ways: no messy wrong-number-of-arguments errors during
macro-expansion, only the actual warnings emitted by the compiler, and
compiler-macros no longer need to be written defensively to avoid such
errors.
This commit is contained in:
Mattias Engdegård
2026-02-28 14:24:35 +01:00
parent f46eaf609e
commit e96bb822e3

View File

@@ -126,8 +126,14 @@ case return FORM unchanged."
form
(apply handler form (cdr form)))
(error
(message "Warning: Optimization failure for %S: Handler: %S\n%S"
(car form) handler err)
;; Don't complain if there's an arity error when calling the handler
;; itself as that is likely the just wrong number of arguments
;; passed to the function; let the compiler take care of it.
(unless (and (eq (car err) 'wrong-number-of-arguments)
(eq (indirect-function (nth 1 err))
(indirect-function handler)))
(message "Warning: Optimization failure for %S: Handler: %S\n%S"
(car form) handler err))
form))))
(defun macroexp--funcall-if-compiled (_form)