luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau-lang.org
MIT License
3.79k stars 349 forks source link

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

Open kalrnlo opened 1 month ago

kalrnlo commented 1 month ago

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)