Subject: bug#51140: 28.0.50; cl-letf appears not to work with native-comp (at least for process-exit-status and other builtins)

From: Robert Irelan <[email-masked]>
Date: Mon, 11 Oct 2021 19:40:54 -0700

I changed the function definition to the following, which I think
doesn't have the free variable problem, and got the same error:

    (defun +ivy--always-return-zero-exit-code-a (fn &rest args)
      (let ((process-exit-status-orig
             (symbol-function 'process-exit-status)))
        (cl-letf* (((symbol-function 'process-exit-status)
                    (lambda (_proc)
                      (let ((code (funcall process-exit-status-orig proc)))
                        (if (= code 2) 0 code)))))
          (apply fn args)))

Interestingly, I now see the error when I evaluate the function
definition, not when I call the advised function.

I think this isolates it to `cl-flet`, since `symbol-function` seems
to return the correct function definition and I can funcall that
definition.

      (let* ((process-exit-status-orig
              (symbol-function 'process-exit-status))
             (proc (start-process-shell-command "true" nil "true")))
        (sleep-for 1)
        (funcall process-exit-status-orig proc))

returns 0, as expected.

On Mon, Oct 11, 2021 at 7:30 PM Michael Heerdegen
<[email-masked]> wrote:
>
> Robert Irelan <[email-masked]> writes:
>
> > (defun +ivy--always-return-zero-exit-code-a (fn &rest args)
> >   (cl-letf* (((symbol-function 'process-exit-status-orig)
> >               (symbol-function 'process-exit-status))
> >              ((symbol-function 'process-exit-status)
> >               (lambda (_proc)
>                          ^^^^^
> >                 (let ((code (process-exit-status-orig proc)))
>                                                         ^^^^
>
> I don't know about native compilation, I just found this free variable
> problem when compiling your defun normally.  You may want to correct
> your recipe.
>
> Michael.

-- 
Robert Irelan
[email-masked]