Hey Emacsers,

I'm likely losing my mind. Is this not a bug, below?

I tried discussing on #emacs first, and then reported (a slightly more complex version). But, it's perhaps not obvious, and it  was suggested I try to produce a simpler example.

I realize I should have discussed it here first, before reporting it.  A discussion here would probably produce a much better bug report in any case.

Do you guys see an obvious bug here? Any simpler versions you can think of?  Any hints where the bug could lie?

Basically, I define a macro that hardcodes the value of our variable ii that existed before the macro definition.

And, then try to use it.


(progn
  (setq lexical-binding nil)

  (dotimes (ii 10)
    (defmacro mac ()
      `(message "%S" ,ii)
      )
    (mac)))


That's the code.
Eval it once. Works.
Eval it again. Works.

Eval it the third time. Debugger entered. Tested in emacs -Q in 28 and 29. [[a]]

In fact, before you eval it the third time, if you change ii to jj, it still complains about ii. [[b]]

Bugs are the behaviors  (a) and (b) above.

The macro expands to (list 'message "%S" ii). That should have worked, right? Because ii was already set at the time of definition? 

Here's the debugger behavior - 
Debugger entered--Lisp error: (void-variable ii)
  (list 'message "%S" ii)