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
+8 -2
View File
@@ -330,6 +330,13 @@ char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = {
"intel",
};
enum UnionTypeKind : u8 {
UnionType_Normal = 0,
UnionType_maybe = 1,
UnionType_no_nil = 2,
UnionType_shared_nil = 3,
};
#define AST_KINDS \
AST_KIND(Ident, "identifier", struct { \
Token token; \
@@ -678,8 +685,7 @@ AST_KIND(_TypeBegin, "", bool) \
Slice<Ast *> variants; \
Ast *polymorphic_params; \
Ast * align; \
bool maybe; \
bool no_nil; \
UnionTypeKind kind; \
Token where_token; \
Slice<Ast *> where_clauses; \
}) \