From 997f11f54322883c3181225f29d101a597f31730 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 24 Aug 2022 17:36:47 -0300 Subject: 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. --- testes/locals.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'testes') diff --git a/testes/locals.lua b/testes/locals.lua index ddb75054..d50beaa5 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -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 -- cgit v1.2.3-55-g6feb