From 7579fc9d7ed90240487251dfb69168f8e64e9294 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 23 Jul 2026 13:58:30 -0300 Subject: Small change in scope of variables in repeat-until A close instruction is still inside the scope of the variables it is closing. The extra close in a repeat-until (to close variables before repeating the loop) was being coded outside that scope. --- testes/locals.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'testes') diff --git a/testes/locals.lua b/testes/locals.lua index 6cd10547..e9718341 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -1179,6 +1179,25 @@ if rawget(_G, "T") then end +do + -- detail in scopes of variables in the loop of 'repeat-until' + local res = {} + local function foo (a) + repeat + local x + local i = setmetatable({}, {__close = function () + res[#res + 1] = debug.getlocal(2, 2) -- get 'x' + res[#res + 1] = debug.getlocal(2, 3) -- get 'i' + a = true + end}) + until a + end + foo(false) + -- loop variables still in scope when closing 'i', both when 'repeat' + -- repeats and when 'repeat' stops. + assert(res[1] == "x" and res[2] == "i" and res[3] == "x" and res[4] == "i") +end + -- to-be-closed variables in generic for loops do -- cgit v1.2.3-55-g6feb