Skip to content

Commit

Permalink
Fix support for zero-sized union variants for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
grassator committed Oct 1, 2023
1 parent b379f96 commit d2daadf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion source.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,14 @@ mass_process_tuple_as_descriptor(
// TODO @Speed if sorting is guaranteed can look only forward and back
for (u64 i = 0; i < dyn_array_length(fields); ++i) {
const Struct_Field *a_field = dyn_array_get(fields, i);
if (range_contains(field_overlap_range, a_field->offset)) {

// In case of a zero-sized field we assume that all fields at a particular
// offset have been set which helps interop with c-style tagged unions
// where one or more of the variants do not have their own fields
if (
a_field->offset >= field_overlap_range.from &&
(range_length(field_overlap_range) == 0 || a_field->offset < field_overlap_range.to)
) {
hash_map_set(assigned_set, a_field, i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion std/prelude.mass
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Never :: &MASS.Descriptor[
.own_module = 0,
.bit_size = [0],
.bit_alignment = [0],
.Pointer_To = [0], // @Hack for C unions
.Never = [],
]
make_never :: fn(allocator : &Allocator, source_range : &MASS.Source_Range) -> (&MASS.Value) {
value := allocate(allocator, MASS.Value)
Expand Down

0 comments on commit d2daadf

Please sign in to comment.