luau icon indicating copy to clipboard operation
luau copied to clipboard

First argument of setmetable throws a type error, if the variable is annotated to be a metatable in the new solver

Open gaymeowing opened this issue 1 year ago • 0 comments

The following code only throws the type error "setmetatable should take a table", only when the export variable is not annotated or tbl in the setmetatable is cast to any

local mt = {
    bar = function(self: any)
		
    end
}
mt.__index = mt
local tbl = {
    foo = 1
}

-- perfectly fine
local export = setmetatable(tbl, mt)

-- setmetatable should take a table
local export: typeof(setmetatable(tbl, mt)) = setmetatable(tbl, mt)

-- fine again
local export: typeof(setmetatable(tbl, mt)) = setmetatable(tbl :: any, mt)

gaymeowing avatar May 23 '24 19:05 gaymeowing