Bug: 'break' may not properly close variable in a 'for' loop

Function 'leaveblock' was generating "break" label before removing
variables from the closing block. If 'createlabel' created a 'close'
instruction (which it did when matching a goto/break that exited
the scope of an upvalue), that instruction would use the wrong level.
This commit is contained in:
Roberto Ierusalimschy
2022-08-24 17:36:47 -03:00
parent 02060b7a37
commit 997f11f543
2 changed files with 28 additions and 8 deletions

View File

@@ -360,6 +360,26 @@ do
end
do
-- bug in 5.4.4: 'break' may generate wrong 'close' instruction when
-- leaving a loop block.
local closed = false
local o1 = setmetatable({}, {__close=function() closed = true end})
local function test()
for k, v in next, {}, nil, o1 do
local function f() return k end -- create an upvalue
break
end
assert(closed)
end
test()
end
do print("testing errors in __close")
-- original error is in __close