luau icon indicating copy to clipboard operation
luau copied to clipboard

Tables with type parameters are not assignable to {[K]:V} in new solver strict mode

Open nothing1649 opened this issue 1 year ago • 0 comments

As of version 0.642, table types with fields being a generic type are incompatible with the table type {[K]:V} in the new solver, causing type errors when passed to functions such as next, table.create or table.isfrozen. This only appears to occur in strict mode.

--!strict
type genericTable<T> = {type:T}
local function nop<K,V>(t:{[K]:V}): () end

local t:genericTable<'any'> = {type = 'any'}
nop(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
table.clear(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
table.isfrozen(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
next(t) --Type Error: (9,6) Type 'genericTable<"any">' could not be converted into '{+ [K]: V +}'

nothing1649 avatar Sep 13 '24 02:09 nothing1649