lua-users home
lua-l archive

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


Excerpt from the Lua grammar:

block : {stat} [retstat] ;
stat : break | ... ;
retstat : return [explist] [';'] ;

"return" is the only "retstat" and thus the only statement that is syntactically only allowed at the end of the block:

(function() return; a = 1 end)()

Is rejected by all Lua versions with the syntax error

'end' expected near ...

Why is this not extended to "break", which is a normal statement and thus allowed to precede arbitrary other statements?

Currently, Lua 5.2 to Lua 5.4 happily allow abominations such as

while true do break break break end
while true do break a = 1 end

and just execute them as expected; Lua 5.1 & LuaJIT however used to throw the syntax error

'end' expected near ...

Is this change in behavior an oversight (regression?) or an intentional change (assuming the latter since the grammar indicates it)? Why should "break" statements be allowed before the end of a block?