[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.4: question about label visibility rule
- From: Albert Krewinkel <albert+lua@...>
- Date: Wed, 19 Jan 2022 14:18:02 +0100
Arnaud Delobelle <email@example.com> writes:
> On Wed, 19 Jan 2022 at 12:18, Albert Krewinkel <firstname.lastname@example.org> wrote:
>> Arnaud Delobelle <email@example.com> writes:
>> > In the Lua 5.4 docs it says the following.
>> > > A label should not be declared where a label with the same
>> > > name is visible, even if this other label has been declared
>> > > in an enclosing block.
>> > I have found the following test in the Lua 5.4.3 Test Suite (available
>> > here: http://www.lua.org/tests/), in the file goto.lua (starting line
>> > 223):
>> > [...]
>> > In this function the label ::l1:: is declared twice, once in the
>> > "elseif a == 4" clause and once at the end of the function. In my
>> > understanding, the second declaration of this label is visible at the
>> > point where the first declaration is made. That would contravene the
>> > rule I have quoted above.
>> I believe the cited paragraph from the docs must be read as a
>> recommendation rather than a rule: the label *should not* be declared,
>> but if people do, the behavior is still well-defined (and tested in the
>> test suite). RFC 2119 phrases it best:
>> > 4. SHOULD NOT This phrase, or the phrase "NOT RECOMMENDED" mean that
>> > there may exist valid reasons in particular circumstances when the
>> > particular behavior is acceptable or even useful, but the full
>> > implications should be understood and the case carefully weighed
>> > before implementing any behavior described with this label.
> Hi Albert,
> It could be an interpretation but I do not think that is the case.
> Take for example the following program:
> ----- testlabel.lua ----
> goto foo
> ---- end ----
> If I run this with Lua 5.4.3 I get the following output:
> lua: testlabel.lua:5: label 'foo' already defined on line 2
> If I run it with Lua 5.3 it compiles and run (forever!). This shows
> that Lua 5.4.3 enforces the rule I quoted (to an extent) so I believe
> my question remains.
Oh, right! Thanks for clarifying, I wasn't aware of that. I'm as puzzled
as you are.
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124