Types from a generalized iteration cannot be compared
ledwastaken opened this issue · 0 comments
ledwastaken commented
--!strict
local Node = {}
Node.__index = Node
export type Node = typeof(setmetatable({} :: {
nodes: {Node}
}, Node))
function Node.new(nodes)
return setmetatable({ nodes = nodes }, Node) :: Node
end
function Node.GetNodes(self: Node)
return self.nodes
end
local node1 = Node.new({})
local node2 = Node.new({node1})
for _, node in node2:GetNodes() do
if node == node1 then
-- ^^^^^^^^^^^^^ TypeError: Types Node and Node cannot be compared with == because they do not have the same metatable
end
end
It seems that types from a generalized iteration are not set correctly when they are using metatables. However it is working when using pairs()
or ipairs()
.