[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: To-Be-Closed For-In-Loop Variable has Problems with Tailcalls
- From: Xmilia Hermit <xmilia.hermit@...>
- Date: Wed, 31 Mar 2021 19:44:45 +0200
Hi,
I think I just found a bug regarding to-be-closed variables. For some
reason the forth to-be-closed variable of a for-in loop has problems to
close with a tailcall as can be seen in the following example.
local function pairs_with_close()
return next, {1}, nil, setmetatable({}, {
__close = function()
print("This should be called")
end
})
end
local function tail()
return 1, 2, 3, setmetatable({}, {
__close = function()
print("Why is this called?")
end
})
end
local function test()
for l in pairs_with_close() --[[io.lines("test.lua")]] do
return tail()
end
end
test()
I would expect the close method from pairs_with_close to be called but
somehow the close method in the tail function is invoked.
Regards,
Xmilia