diff options
| author | gingerBill <bill@gingerbill.org> | 2023-05-19 12:11:18 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-05-19 12:11:18 +0100 |
| commit | 4201834b18e540b64899d27f7426fc98cce457c3 (patch) | |
| tree | 1f23ed1d13b81b52c8295f380be19c0a055b210d /src/check_builtin.cpp | |
| parent | 2631e07beab29558249341c329c69bb604dd61fb (diff) | |
Make `intrinsics.type_merge` form a union of the types; ignoring duplicates
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 0f8cdfd69..46ee6b7f9 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -4902,10 +4902,24 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As merged_union->Union.kind = ux->Union.kind; merged_union->Union.custom_align = custom_align; - auto variants = slice_make<Type *>(permanent_allocator(), ux->Union.variants.count+uy->Union.variants.count); - slice_copy(&variants, ux->Union.variants, 0); - slice_copy(&variants, uy->Union.variants, ux->Union.variants.count); - merged_union->Union.variants = variants; + auto variants = array_make<Type *>(permanent_allocator(), 0, ux->Union.variants.count+uy->Union.variants.count); + for (Type *t : ux->Union.variants) { + array_add(&variants, t); + } + for (Type *t : uy->Union.variants) { + bool ok = true; + for (Type *other_t : ux->Union.variants) { + if (are_types_identical(other_t, t)) { + ok = false; + break; + } + } + if (ok) { + array_add(&variants, t); + } + + } + merged_union->Union.variants = slice_from_array(variants); operand->mode = Addressing_Type; operand->type = merged_union; |