luau icon indicating copy to clipboard operation
luau copied to clipboard

[new solver] Checking for nonexistent property on table type causes a type refinement with no error

Open nothing1649 opened this issue 9 months ago • 0 comments

As of version 0.665, checking for a property on a table type where the key does not exist does not cause an error, and instead adds the key to the type with ~(false?). This causes silent errors in multiple cases that the typechecker does not report, for example if a typo occurs or the property has been renamed.

--!strict
local foo:{val:number} = {val = 1}
--no type error, adds property to table when it probably shouldn't
if foo.vall then
	--type is refined to {val: number, vall: ~(false?)}
	print(foo.vall)
end

nothing1649 avatar Mar 16 '25 18:03 nothing1649