diff options
Diffstat (limited to 'testes/locals.lua')
-rw-r--r-- | testes/locals.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index 4f103be9..0e5e0c74 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -264,6 +264,43 @@ do end +-- testing to-be-closed x compile-time constants +-- (there were some bugs here in Lua 5.4-rc3, due to a confusion +-- between compile levels and stack levels of variables) +do + local flag = false + local x = setmetatable({}, + {__close = function() assert(flag == false); flag = true end}) + local y <const> = nil + local z <const> = nil + do + local a <close> = x + end + assert(flag) -- 'x' must be closed here +end + +do + -- similar problem, but with implicit close in for loops + local flag = false + local x = setmetatable({}, + {__close = function () assert(flag == false); flag = true end}) + -- return an empty iterator, nil, nil, and 'x' to be closed + local function a () + return (function () return nil end), nil, nil, x + end + local v <const> = 1 + local w <const> = 1 + local x <const> = 1 + local y <const> = 1 + local z <const> = 1 + for k in a() do + a = k + end -- ending the loop must close 'x' + assert(flag) -- 'x' must be closed here +end + + + do -- calls cannot be tail in the scope of to-be-closed variables local X, Y |