You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The second case (__add is not defined in rec_mt) is unlikely to be supported soon (the compiler currently does not do nil checks in general), but the first one sounds like it should have been checked — (note to self: this may require some adding custom code for checking setmetatable arguments, similarly to how we handle pcall, etc.).
OK, so my understanding for the second case: the record definition defines what keys/values are valid, but not that they are defined (or more generally perhaps the values may be nil, since nil is a valid value of every type). What is checked is that values for the defined keys have the right type, and that no other keys are added to the record.
For the first case, I guess the safest place to check is at setmetatable.
local r: Rec = setmetatable({ }, rec_mt)
I assume the inferred type of { } here is Rec, thanks to the assignment to r: Rec? And thus rec_mt must be metatable<Rec>, which in turn should satisfy the metamethods of Rec?
You could (should?) also check at the assignment to rec_mt that it satisfies the metamethods of Rec, since rec_mt is declared as a metatable<Rec>.
Currently it seems the metatable<Rec> type does nothing at all:
The contents of rec_mt are not checked versus Recs metamethods.
setmetatable does not check that rec_mt is a metatable<Rec> (it will accept any table, including of type metatable<SomeOtherType>).
Hi, is the below code supposed to pass the typechecker? (The type of
__add
inrec_mt
does not have the correct type formetamethod __add
inRec
.)What about this one? (
__add
is not defined inrec_mt
)The text was updated successfully, but these errors were encountered: