luau
luau copied to clipboard
table.insert incorrect or missing type error message, fails to cast
local t: { string } = {}
table.insert(t, 1) -- does not error but should, 1 is not a string
table.insert(t, true) -- TypeError: Type 'boolean' could not be converted into 'number'
-- TypeError: Available overloads: <V>({V}, V) -> (); and <V>({V}, number, V) -> ()
local t2: { { a: string? } } = {}
table.insert(t2, { a = "b" }) -- TypeError: Type '{ a: string }' could not be converted into 'number'
local t3: { { a: "a" } } = {}
table.insert(t3, { a = "a" }) -- TypeError: Type '{ a: string }' could not be converted into 'number'
if table.insert is used and the type of the element being inserted isn't correct, the error incorrectly blames that it couldn't cast it to a number, rather than that it couldn't cast it to the type that the table is supposed to contain. table.insert also accepts a number in the second argument without erroring, even when it should. it also seems to fail to cast types that should be allowed, then incorrectly complaining about them not being a number.
Thanks for the report! The first couple issues should have fix(es) coming out soon.
local t3: { { a: "a" } } = {}
table.insert(t3, { a = "a" }) -- TypeError: Type '{ a: string }' could not be converted into 'number'
This one is a little trickier, so hold on for a fix there.