Subject: Re: bug#5728: Byte compile doesn't work right on macro

From: Stefan Monnier <[email-masked]>
Date: Thu, 08 Apr 2010 16:02:55 -0400

> When I byte-compile certain code, the results are different than when
> it's not byte-compiled.  It seems to wrongly merge lists.  The one
> unusual thing I was doing with the code is using a macro to generate a
> call to a ctor (as generated by defstruct)

You're victim of a form of "name capture".
E.g. if you rename `a' to `b' in BUG3, the bug disappears.
And if you macroexpand by hand the call to BUG:make-form the bug is
still there.

More to the point, the bug is in the compiler-macro for
BUG:make-structure:

   ELISP> (compiler-macroexpand '(BUG:make-structure :edits (cons (car a) (BUG:structure->edits cand)) :a nil))
   (block BUG:make-structure
     (vector 'cl-struct-BUG:structure
   	  (cons (car nil) (BUG:structure->edits cand))
   	  nil))
   ELISP> (defsubst* toto (a1 a2) (+ a1 a2))
   toto
   ELISP> (compiler-macroexpand '(toto a2 nil))
   (block toto (+ nil nil))
   
   ELISP> 

The problem is that cl-defsubst-expand does the substitution "a1 -> a2
and a2 -> nil" one after the other rather than simultaneously.

I've just installed a fix for it in the emacs-23 branch.

        Stefan