lua-users home
lua-l archive

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


Arnaud Delobelle <arnodel@gmail.com> writes:

> On Wed, 19 Jan 2022 at 12:18, Albert Krewinkel <albert+lua@zeitkraut.de> wrote:
>>
>>
>> Arnaud Delobelle <arnodel@gmail.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:
>> <https://datatracker.ietf.org/doc/html/rfc2119>
>>
>> > 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 ----
> do
>     ::foo::
>     do
>         ::foo::
>         goto foo
>     end
> end
> ---- 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.


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124