mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Unwrap the struct inside a single-tag union
This commit is contained in:
parent
2337d6638e
commit
cdce98d14f
2 changed files with 23 additions and 11 deletions
|
@ -525,18 +525,24 @@ pub fn build_expr<'a, 'ctx, 'env>(
|
|||
field_vals.push(val);
|
||||
}
|
||||
|
||||
// Create the struct_type
|
||||
let struct_type = ctx.struct_type(field_types.into_bump_slice(), false);
|
||||
let mut struct_val = struct_type.const_zero().into();
|
||||
// If the struct has only one field that isn't zero-sized,
|
||||
// unwrap it. This is what the layout expects us to do.
|
||||
if field_vals.len() == 1 {
|
||||
field_vals.pop().unwrap()
|
||||
} else {
|
||||
// Create the struct_type
|
||||
let struct_type = ctx.struct_type(field_types.into_bump_slice(), false);
|
||||
let mut struct_val = struct_type.const_zero().into();
|
||||
|
||||
// Insert field exprs into struct_val
|
||||
for (index, field_val) in field_vals.into_iter().enumerate() {
|
||||
struct_val = builder
|
||||
.build_insert_value(struct_val, field_val, index as u32, "insert_field")
|
||||
.unwrap();
|
||||
// Insert field exprs into struct_val
|
||||
for (index, field_val) in field_vals.into_iter().enumerate() {
|
||||
struct_val = builder
|
||||
.build_insert_value(struct_val, field_val, index as u32, "insert_field")
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
BasicValueEnum::StructValue(struct_val.into_struct_value())
|
||||
}
|
||||
|
||||
BasicValueEnum::StructValue(struct_val.into_struct_value())
|
||||
}
|
||||
Tag {
|
||||
arguments,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue