Equality comparison between generic type + type w/ metatable fails
local plr: Player = game.Players.LocalPlayer
local function foo(bar)
if bar == plr then
-- ^^^^^^^^^^ TypeError: Types a and Player cannot be compared with == because they do not have the same metatable
end
end
I would expect inference to produce a less strict generic type so that this doesn't error and instead we expect an __eq metamethod constraint on bar for ==
Firstly: we do not have a mechanism to place bounds on generics. This is planned for the future, but isn't here yet. It wouldn't be very useful in this case, though, because bar would have to be of type Player for the comparison to function in the current scheme, and at that point you don't need a generic.
However, this comparison should not be producing an error at all, because there is a situation where it could happen! Our intent with this error was to highlight cases where a comparison is guaranteed to evaluate to false (because of the rules for when the __eq metamethod is invoked). However, in this code sample, we have a comparison of a free type (at the point when the == expression is being checked; it's converted to a generic later) with a ClassTypeVar. We don't know whether bar is comparable with plr based solely on the definition of foo. Our stance here is that we don't want to report an error in this case.
I've opened a tracking issue internally for this; we'll try to nail this down.