Subject: Re: bug#50034: 28.0.50; elisp capf error "Wrong type argument: listp, elisp--witness--lisp"
From: Stefan Monnier <[email-masked]>
To: Lars Ingebrigtsen <[email-masked]>
Cc: Daniel Mendler <[email-masked]>, [email-masked]
Date: Tue, 23 Aug 2022 10:17:52 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> Slightly simpler repro:
>
> (defmacro foo bar
> M-: (elisp--local-variables) RET
>
> It fails here:
>
>                     (`(lambda ,args . ,body)
>                      (elisp--local-variables-1
>                       (append (remq '&optional (remq '&rest args)) vars)
>                       (car (last body))))
>
> where it expects args to be a list, but it's the symbol
> `elisp--witness--lisp'.

Since the code can be completely non-sensical, `elisp--local-variables`
shouldn't presume that the arglist is indeed a list.  I installed the fix
below on `master`.

        Stefan

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 0c4a9bfdbea..6d8ced7f220 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -383,7 +383,9 @@ elisp--local-variables-1
                      (setq sexp nil))
                     (`(lambda ,args . ,body)
                      (elisp--local-variables-1
-                      (append (remq '&optional (remq '&rest args)) vars)
+                      (let ((args (if (listp args) args)))
+                        ;; FIXME: Exit the loop if witness is in args.
+                        (append (remq '&optional (remq '&rest args)) vars))
                       (car (last body))))
                     (`(condition-case ,_ ,e) (elisp--local-variables-1 vars e))
                     (`(condition-case ,v ,_ . ,catches)