Subject: bug#19704: 25.0.50; funcall with hard-quote inside cl-labels uses the local function binding

From: Dmitry Gutov <[email-masked]>
Date: Sat, 11 Jun 2016 01:06:55 +0300

On 06/10/2016 05:37 AM, Noam Postavsky wrote:

> Seems that macroexp--expand-all got too aggressive, patch below
> teaches it to back off in case of locally defined functions:

Thanks, Noam. Seems to work fine here.

Stefan, how does it look to you?

Eli, can we have it in emacs-25 (it's a regression)?

> diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
> index ed4d6e4..ce5d5dc 100644
> --- a/lisp/emacs-lisp/macroexp.el
> +++ b/lisp/emacs-lisp/macroexp.el
> @@ -261,9 +261,14 @@ macroexp--expand-all
>          (format "%s quoted with ' rather than with #'"
>                  (list 'lambda (nth 1 f) '...))
>          (macroexp--expand-all `(,fun ,arg1 ,f . ,args))))
> -      (`(funcall (,(or 'quote 'function) ,(and f (pred symbolp)) . ,_) . ,args)
> -       ;; Rewrite (funcall #'foo bar) to (foo bar), in case `foo'
> -       ;; has a compiler-macro.
> +      ;; Rewrite (funcall #'foo bar) to (foo bar), in case `foo'
> +      ;; has a compiler-macro.
> +      (`(funcall (,(or 'quote 'function)
> +                  ,(and f (pred symbolp)
> +                        ;; Unless `foo' is a locally bound macro.
> +                        (guard (not (assq f macroexpand-all-environment))))
> +                  . ,_)
> +                 . ,args)
>         (macroexp--expand-all `(,f . ,args)))
>        (`(,func . ,_)
>         ;; Macro expand compiler macros.  This cannot be delayed to
>