diff options
| author | gingerBill <bill@gingerbill.org> | 2019-07-09 10:28:13 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-07-09 10:28:13 +0100 |
| commit | 4ab9edeb53559f6ab6ef39a5ad9b45564d22aa8e (patch) | |
| tree | 02ece312f83cfb4e5b3873d88b64950369c883e0 /src/types.cpp | |
| parent | c5b3d7a73640b3d3cbf3309cc2e61790a4901da6 (diff) | |
union #no_nil
Diffstat (limited to 'src/types.cpp')
| -rw-r--r-- | src/types.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/types.cpp b/src/types.cpp index 875519f2d..dc7ecb946 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -131,6 +131,7 @@ struct TypeUnion { i64 variant_block_size; i64 custom_align; i64 tag_size; + bool no_nil; bool is_polymorphic; bool is_poly_specialized; @@ -1468,7 +1469,7 @@ bool type_has_nil(Type *t) { case Type_Map: return true; case Type_Union: - return true; + return !t->Union.no_nil; case Type_Struct: return false; case Type_Opaque: @@ -1625,7 +1626,8 @@ bool are_types_identical(Type *x, Type *y) { case Type_Union: if (y->kind == Type_Union) { if (x->Union.variants.count == y->Union.variants.count && - x->Union.custom_align == y->Union.custom_align) { + x->Union.custom_align == y->Union.custom_align && + x->Union.no_nil == y->Union.no_nil) { // NOTE(bill): zeroth variant is nullptr for_array(i, x->Union.variants) { if (!are_types_identical(x->Union.variants[i], y->Union.variants[i])) { @@ -1778,7 +1780,11 @@ i64 union_variant_index(Type *u, Type *v) { for_array(i, u->Union.variants) { Type *vt = u->Union.variants[i]; if (are_types_identical(v, vt)) { - return cast(i64)(i+1); + if (u->Union.no_nil) { + return cast(i64)(i+0); + } else { + return cast(i64)(i+1); + } } } return 0; |