union #shared_nil

This adds a feature to `union` which requires all the variants to have a `nil` value and on assign to the union, checks whether that value is `nil` or not. If the value is `nil`, the union will be `nil` (thus sharing the `nil` value)
This commit is contained in:
gingerBill
2022-03-24 11:55:03 +00:00
parent 3e66eec735
commit 3f935bea25
10 changed files with 104 additions and 32 deletions

View File

@@ -10047,8 +10047,11 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) {
str = write_expr_to_string(str, st->polymorphic_params, shorthand);
str = gb_string_appendc(str, ") ");
}
if (st->no_nil) str = gb_string_appendc(str, "#no_nil ");
if (st->maybe) str = gb_string_appendc(str, "#maybe ");
switch (st->kind) {
case UnionType_maybe: str = gb_string_appendc(str, "#maybe "); break;
case UnionType_no_nil: str = gb_string_appendc(str, "#no_nil "); break;
case UnionType_shared_nil: str = gb_string_appendc(str, "#shared_nil "); break;
}
if (st->align) {
str = gb_string_appendc(str, "#align ");
str = write_expr_to_string(str, st->align, shorthand);