diff options
| author | gingerBill <bill@gingerbill.org> | 2022-03-24 11:55:03 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-03-24 11:55:03 +0000 |
| commit | 3f935bea2505b3ee7e169a29b7aed50c0e5614b7 (patch) | |
| tree | 3d3886ccfe8146a2226703c1d10b7908f3b54e3b /src/check_expr.cpp | |
| parent | 3e66eec7354a8248fe8e0edfccbdc9e8b203e88a (diff) | |
`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)
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 66bf8bbd7..dcf17af39 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -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); |