Fixed two bugs in to-be-closed variables x constants
The parser were mixing compiler indices of variables with stack indices, so that when a to-be-closed variable was used inside the scope of compile-time constants (which may be optimized away), it might be closed in the wrong place. (See new tests for examples.) Besides fixing the bugs, this commit also changed comments and variable names to avoid that kind of confusion and added tests.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user