Closed paulsgcross closed 7 months ago
Nil-checking has already been asked for several times. Please see #598 and following discussions. Closing this one as a duplicate, thanks for understanding!
Yep, totally understand. Not sure if I added much to the discussion but will continue to funnel any thoughts into those open issues :)
Apologies if this is already a feature.
Context
Currently, it is possible to do this:
This is fine and supported by the Lua syntax (it is equivilant to 'assigning' nil to every field) and so no reason to prevent it. However, there would be benefit to optionally enforce that specific (or all) Record fields must not be 'nil' when passed into a function or declared as a type - compiler-side.
Proposal
When defining records, allow the programmer to set fields as
<required>
(a different name to distinguish fromrequire
would be better):Likewise, if you're lazy and don't want to be forced to set this for every field:
This would be the equivilent of adding
<required>
to every field.Anything that matches the required record signature should also be accepted as to allow for polymorphism and the ability to substitute records with 'sub-types':
Pros
Cons