lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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