| ... | ... | @@ -1484,17 +1484,15 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1487 | | IrInstruction *container_type, IrInstruction *elem_type, size_t item_count, IrInstruction **items) |
| 1487 | IrInstruction *container_type, size_t item_count, IrInstruction **items) |
| 1488 | 1488 | { |
| 1489 | 1489 | IrInstructionContainerInitList *container_init_list_instruction = |
| 1490 | 1490 | ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node); |
| 1491 | 1491 | container_init_list_instruction->container_type = container_type; |
| 1492 | | container_init_list_instruction->elem_type = elem_type; |
| 1493 | 1492 | container_init_list_instruction->item_count = item_count; |
| 1494 | 1493 | container_init_list_instruction->items = items; |
| 1495 | 1494 | |
| 1496 | | if (container_type != nullptr) ir_ref_instruction(container_type, irb->current_basic_block); |
| 1497 | | if (elem_type != nullptr) ir_ref_instruction(elem_type, irb->current_basic_block); |
| 1495 | ir_ref_instruction(container_type, irb->current_basic_block); |
| 1498 | 1496 | for (size_t i = 0; i < item_count; i += 1) { |
| 1499 | 1497 | ir_ref_instruction(items[i], irb->current_basic_block); |
| 1500 | 1498 | } |
| ... | ... | @@ -5620,11 +5618,17 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5620 | 5618 | src_assert(result_loc->scope_elide == nullptr, node); |
| 5621 | 5619 | result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope); |
| 5622 | 5620 | |
| 5621 | size_t item_count = container_init_expr->entries.length; |
| 5622 | |
| 5623 | if (container_type == nullptr) { |
| 5624 | IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 5625 | container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type); |
| 5626 | } |
| 5627 | |
| 5623 | 5628 | src_assert(result_loc != nullptr, node); |
| 5624 | 5629 | IrInstruction *container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base, |
| 5625 | 5630 | node, result_loc, container_type); |
| 5626 | 5631 | |
| 5627 | | size_t item_count = container_init_expr->entries.length; |
| 5628 | 5632 | IrInstruction **values = allocate<IrInstruction *>(item_count); |
| 5629 | 5633 | for (size_t i = 0; i < item_count; i += 1) { |
| 5630 | 5634 | AstNode *expr_node = container_init_expr->entries.at(i); |
| ... | ... | @@ -5644,7 +5648,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5644 | 5648 | |
| 5645 | 5649 | values[i] = expr_value; |
| 5646 | 5650 | } |
| 5647 | | IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, elem_type, |
| 5651 | IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, |
| 5648 | 5652 | item_count, values); |
| 5649 | 5653 | return ir_lval_wrap(irb, scope, init_list, lval, result_loc); |
| 5650 | 5654 | } |
| ... | ... | @@ -18538,22 +18542,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 18538 | 18542 | { |
| 18539 | 18543 | Error err; |
| 18540 | 18544 | |
| 18541 | | size_t elem_count = instruction->item_count; |
| 18545 | ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child); |
| 18546 | if (type_is_invalid(container_type)) |
| 18547 | return ira->codegen->invalid_instruction; |
| 18542 | 18548 | |
| 18543 | | ZigType *container_type; |
| 18544 | | if (instruction->container_type != nullptr) { |
| 18545 | | container_type = ir_resolve_type(ira, instruction->container_type->child); |
| 18546 | | if (type_is_invalid(container_type)) |
| 18547 | | return ira->codegen->invalid_instruction; |
| 18548 | | } else { |
| 18549 | | ZigType *elem_type = ir_resolve_type(ira, instruction->elem_type->child); |
| 18550 | | if (type_is_invalid(elem_type)) |
| 18551 | | return ira->codegen->invalid_instruction; |
| 18552 | | if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) { |
| 18553 | | return ira->codegen->invalid_instruction; |
| 18554 | | } |
| 18555 | | container_type = get_array_type(ira->codegen, elem_type, elem_count); |
| 18556 | | } |
| 18549 | size_t elem_count = instruction->item_count; |
| 18557 | 18550 | |
| 18558 | 18551 | if (is_slice(container_type)) { |
| 18559 | 18552 | ir_add_error(ira, &instruction->base, |