On Aug 26, 2013, at 4:16 PM, Andrew Starks <email@example.com> wrote:
Of course, as I said it was just a silly typo on my part. My point, however, was that the reuse of stack slots by the compiler involves more than just a quick check to see if the new local name matches any existing one at the same scope.
If memory serves me right, the upvalue in foo() that references the first "a" still references the stack slot (hence it changing to 2 as per your example). it's only when the containing function goes out of scope that Lua has to migrate the upvalue off the stack.