diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-29 10:28:16 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-29 10:28:16 +0100 |
| commit | 10ba956d6a57cb5b334b4311cda96c6c7f8737db (patch) | |
| tree | 6276240a0153e407ce7e2c21133f95fc3bc02913 /src/types.cpp | |
| parent | 1f2cedcf78907c7cb2d743cc476f11981a06e32b (diff) | |
Rudimentary support for some constant `struct #raw_union`
Diffstat (limited to 'src/types.cpp')
| -rw-r--r-- | src/types.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/types.cpp b/src/types.cpp index 62e47259d..1fbcd429b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2531,6 +2531,20 @@ gb_internal bool is_type_union_constantable(Type *type) { return true; } +gb_internal bool is_type_raw_union_constantable(Type *type) { + Type *bt = base_type(type); + GB_ASSERT(bt->kind == Type_Struct); + GB_ASSERT(bt->Struct.is_raw_union); + + for (Entity *f : bt->Struct.fields) { + if (!is_type_constant_type(f->type)) { + return false; + } + } + return true; +} + + gb_internal bool elem_type_can_be_constant(Type *t) { t = base_type(t); if (t == t_invalid) { @@ -2540,7 +2554,7 @@ gb_internal bool elem_type_can_be_constant(Type *t) { return false; } if (is_type_raw_union(t)) { - return false; + return is_type_raw_union_constantable(t); } if (is_type_union(t)) { return is_type_union_constantable(t); @@ -2556,7 +2570,7 @@ gb_internal bool elem_cannot_be_constant(Type *t) { return !is_type_union_constantable(t); } if (is_type_raw_union(t)) { - return true; + return !is_type_raw_union_constantable(t); } return false; } |