[New Solver] Intersection of types producing does not have key error
Consider this code:
local function runCode(billboard: BillboardGui & {
TextLabel: TextLabel,
}): ()
billboard.TextLabel.Text = "Hello"
end
this produces an error:
TypeError: Type 'BillboardGui & { TextLabel: TextLabel }' does not have key 'TextLabel'
which is certainly an error -- there clearly is a key for TextLabel!
Notabaly, reversing the order when defining billboard does not produce the error:
local function runCode(billboard: {
TextLabel: TextLabel,
} & BillboardGui): ()
billboard.TextLabel.Text = "Hello"
end
produces no type errors today (which is good!).
The former should also not produce a type error, because the intersection should be commutative.
Ditto on this one. Gets fixed when you switch the order of the intersection type. The rbxutil/TypedRemote module I use had Instance joined by an intersection with a table type annotation, and it breaks with this bug. There was a proposal to modify the library to adjust to this issue, but there is a strong preference to have the issue resolved on the Luau side since this affects more than just the library
"Temporary fix" (Moving & Instance after the table type):
The expected behavior for both of these is that the intersection is never because table types and extern types are disjoint, and so have no common values, but we have not fixed this because obviously everyone attempting to do this kind of "refine what properties are on an extern type" programming would be even more unhappy with that being fixed right now. This requires a much more systemic fix to how we approach users specifying specific extern types.