lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 4/19/07, Thomas Lauer <thomas.lauer@virgin.net> wrote:
It wouldn't be a bad idea, IMHO, if this sentence would be changed to
say this is true even for multiple identical local definitions in the
same scope.

It does already say this:

"The scope of variables begins at the first statement after their
declaration and lasts until the end of the innermost block ..."

A block is not a scope -- there is no scope expect where there is a
(local) variable to have one.  The only way for multiple definitions
to have the same scope is that they are declared in the same statement
(or parameter list).  In this case, the last variable of the same name
overrides the previous ones, if any:

local a,a,a = 1,2,3; print(a) -- prints 3
(function(a,a,a) print(a); end)(1,2,3) -- prints 3

I've had to deal with scope bugs related to having a variable of the
same name before too.  Having a compiler warning might be a good
thing.

    -Mark