diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-28 20:20:26 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-28 20:20:26 +0100 |
| commit | ffdfbfe2c2d0e09087f166be79f3dbc2859844e6 (patch) | |
| tree | d934e3db6ca1a7129ddac3654f8bc4af6114edc5 /src/types.cpp | |
| parent | a974c51d573618c9cc4496a32885b7f871c317b2 (diff) | |
Begin to support constant array of unions
Diffstat (limited to 'src/types.cpp')
| -rw-r--r-- | src/types.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/types.cpp b/src/types.cpp index 0c6702103..46e41bb4b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2507,15 +2507,35 @@ gb_internal bool type_has_nil(Type *t) { return false; } +gb_internal bool is_type_union_constantable(Type *type) { + Type *bt = base_type(type); + GB_ASSERT(bt->kind == Type_Union); + + if (bt->Union.variants.count == 0) { + return true; + } else if (bt->Union.variants.count == 1) { + return is_type_constant_type(bt->Union.variants[0]); + } + + for (Type *v : bt->Union.variants) { + if (!is_type_constant_type(v)) { + return false; + } + } + return true; +} gb_internal bool elem_type_can_be_constant(Type *t) { t = base_type(t); if (t == t_invalid) { return false; } - if (is_type_any(t) || is_type_union(t) || is_type_raw_union(t)) { + if (is_type_any(t) || is_type_raw_union(t)) { return false; } + if (is_type_union(t)) { + return is_type_union_constantable(t); + } return true; } |