lua-users home
lua-l archive

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


Hi Arnaud,
would it not be easier that you just avoid such situation by using
different label name? (I do not see any reason why this should not
work? Label names you can invent as you names, you just need some
phantasy to use more fancy label names to get more of them very
easily?)

On Wed, Jan 19, 2022 at 11:25 AM Arnaud Delobelle <arnodel@gmail.com> wrote:
>
> Hi all,
>
> 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):
>
> local function testG (a)
>   if a == 1 then
>     goto l1
>     error("should never be here!")
>   elseif a == 2 then goto l2
>   elseif a == 3 then goto l3
>   elseif a == 4 then
>     goto l1 -- go to inside the block
>     error("should never be here!")
>     ::l1:: a = a + 1 -- FIRST DECLARATION OF l1
>   else
>     goto l4
>     ::l4a:: a = a * 2; goto l4b
>     error("should never be here!")
>     ::l4:: goto l4a
>     error("should never be here!")
>     ::l4b::
>   end
>   do return a end
>   ::l2:: do return "2" end
>   ::l3:: do return "3" end
>   ::l1:: return "1" -- SECOND DECLARATION OF l1
> end
>
> 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.
>
> This must mean that I am misunderstanding the meaning of the quoted
> rule.  Could anyone please help me understand it?
>
> Regards,
>
> --
> Arnaud