diff --git a/lparser.c b/lparser.c index fe29194c..3c26a4fd 100644 --- a/lparser.c +++ b/lparser.c @@ -1614,7 +1614,6 @@ static void repeatstat (LexState *ls, int line) { statlist(ls); check_match(ls, TK_UNTIL, TK_REPEAT, line); condexit = cond(ls); /* read condition (inside scope block) */ - leaveblock(fs); /* finish scope */ if (bl2.upval) { /* upvalues? */ int exit = luaK_jump(fs); /* normal exit must jump over fix */ luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ @@ -1623,6 +1622,7 @@ static void repeatstat (LexState *ls, int line) { luaK_patchtohere(fs, exit); /* normal exit comes to here */ } luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ + leaveblock(fs); /* finish scope */ leaveblock(fs); /* finish loop */ } 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