tl icon indicating copy to clipboard operation
tl copied to clipboard

Generic's type is always assumed to be a table even when it isn't

Open Frityet opened this issue 3 months ago • 0 comments

local record Box<T> where (function(k: any): boolean return k is T end)(self.children[1])
    children: {any}
end

local a: Box<integer> | Box<string> = (function(): Box<integer> return { children = { 1 } } end)()

if not a is Box<integer> then error "pluh" end

errors with pluh, even though it should be valid, this is because the code generates to

local a = (function() return { children = { 1, "two", "thrwee" } } end)(); if not (function(k) return type(k) == "table"





end)(a.children[1]) then error("pluh") end

whilst it should be math.type(k) == "integer"

Frityet avatar Nov 30 '25 16:11 Frityet