Subject: Re: bug#30872: incorrect byte-compile of closure called from local funcalled function

From: Noam Postavsky <[email-masked]>
Date: Wed, 30 May 2018 18:55:33 -0400

I narrowed it down a bit more, note the lack of setq in the result of
byte-compile-preprocess:

(byte-compile-preprocess
 '#'(lambda (handle-fun arg)
      (let* ((subfun #'(lambda (params)
                         (ignore handle-fun)
                         (funcall #'(lambda () (setq params nil)))
                         params)))
        (funcall subfun arg))))
;=>
#'(lambda (handle-fun arg)
    (let* ((subfun
            #'(lambda (handle-fun params)
                (ignore handle-fun)
                (funcall
                 (internal-make-closure nil
                                        (params)
                                        nil nil))
                params)))
      (funcall subfun handle-fun arg)))

It's hitting this bit of code in cconv.el, where it says this "should
never happen":

(defun cconv-convert (form env extend)
  (pcase form
    [...]
    (`(setq . ,forms)                   ; setq special form
      [...]
             (push (pcase sym-new
                     ((pred symbolp) `(setq ,sym-new ,value))
                     (`(car-safe ,iexp) `(setcar ,iexp ,value))
                     ;; This "should never happen", but for variables which are
                     ;; mutated+captured+unused, we may end up trying to `setq'
                     ;; on a closed-over variable, so just drop the setq.
                     (_ ;; (byte-compile-report-error
                      ;;  (format "Internal error in cconv of (setq %s ..)"
                      ;;          sym-new))
                      value))

Stefan, thoughts?