[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: multiple local definitions in the same scope
- From: Thomas Lauer <thomas.lauer@...>
- Date: Fri, 20 Apr 2007 09:32:51 +0100
"Mark Edgar" <firstname.lastname@example.org> wrote:
> 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).
Perhaps I misunderstand you but I think that's not the case. You can
have one statement with a local declaration at the top of the file and
several longish functions later you can have another declaration that
silently overrides the first:
-- and much more blahblahX()
I am not arguing that this shouldn't happen, I am just saying that it
came as a surprise and that the manual could usefully give an explicit
warning in section 2.3 as well.
> (function(a,a,a) print(a); end)(1,2,3) -- prints 3
I have noticed that too and I must say that this specific case leaves me
with a certain strange feeling. Having two parameters with the same name
is almost 100% an error, so a warning might be appropriate... if the
compiler could warn.
Anyway, it's not a big deal, just something that might make the life of
other newbies a little easier.