| ... | ... | @@ -17526,6 +17526,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 17526 | 17526 | extra_index += bit_bags_count; |
| 17527 | 17527 | var cur_bit_bag: u32 = undefined; |
| 17528 | 17528 | var field_i: u32 = 0; |
| 17529 | var last_tag_val: ?Value = null; |
| 17529 | 17530 | while (field_i < fields_len) : (field_i += 1) { |
| 17530 | 17531 | if (field_i % fields_per_u32 == 0) { |
| 17531 | 17532 | cur_bit_bag = zir.extra[bit_bag_index]; |
| ... | ... | @@ -17566,15 +17567,26 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 17566 | 17567 | } else .none; |
| 17567 | 17568 | |
| 17568 | 17569 | if (enum_value_map) |map| { |
| 17569 | | const tag_src = src; // TODO better source location |
| 17570 | | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 17571 | | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced); |
| 17572 | | |
| 17573 | | // This puts the memory into the union arena, not the enum arena, but |
| 17574 | | // it is OK since they share the same lifetime. |
| 17575 | | const copied_val = try val.copy(decl_arena_allocator); |
| 17576 | | |
| 17577 | | map.putAssumeCapacityContext(copied_val, {}, .{ .ty = int_tag_ty }); |
| 17570 | if (tag_ref != .none) { |
| 17571 | const tag_src = src; // TODO better source location |
| 17572 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 17573 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced); |
| 17574 | last_tag_val = val; |
| 17575 | |
| 17576 | // This puts the memory into the union arena, not the enum arena, but |
| 17577 | // it is OK since they share the same lifetime. |
| 17578 | const copied_val = try val.copy(decl_arena_allocator); |
| 17579 | map.putAssumeCapacityContext(copied_val, {}, .{ .ty = int_tag_ty }); |
| 17580 | } else { |
| 17581 | const val = if (last_tag_val) |val| |
| 17582 | try val.intAdd(Value.one, sema.arena) |
| 17583 | else |
| 17584 | Value.zero; |
| 17585 | last_tag_val = val; |
| 17586 | |
| 17587 | const copied_val = try val.copy(decl_arena_allocator); |
| 17588 | map.putAssumeCapacityContext(copied_val, {}, .{ .ty = int_tag_ty }); |
| 17589 | } |
| 17578 | 17590 | } |
| 17579 | 17591 | |
| 17580 | 17592 | // This string needs to outlive the ZIR code. |