| ... | ... | @@ -8111,7 +8111,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * |
| 8111 | 8111 | *errors = reallocate(*errors, old_errors_count, *errors_count); |
| 8112 | 8112 | } |
| 8113 | 8113 | |
| 8114 | | static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) { |
| 8114 | static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, TypeTableEntry *expected_type, IrInstruction **instructions, size_t instruction_count) { |
| 8115 | 8115 | assert(instruction_count >= 1); |
| 8116 | 8116 | IrInstruction *prev_inst = instructions[0]; |
| 8117 | 8117 | if (type_is_invalid(prev_inst->value.type)) { |
| ... | ... | @@ -8158,16 +8158,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8158 | 8158 | continue; |
| 8159 | 8159 | } |
| 8160 | 8160 | |
| 8161 | | if (prev_type->id == TypeTableEntryIdNullLit) { |
| 8162 | | prev_inst = cur_inst; |
| 8163 | | continue; |
| 8164 | | } |
| 8165 | | |
| 8166 | | if (cur_type->id == TypeTableEntryIdNullLit) { |
| 8167 | | any_are_null = true; |
| 8168 | | continue; |
| 8169 | | } |
| 8170 | | |
| 8171 | 8161 | if (prev_type->id == TypeTableEntryIdErrorSet) { |
| 8172 | 8162 | assert(err_set_type != nullptr); |
| 8173 | 8163 | if (cur_type->id == TypeTableEntryIdErrorSet) { |
| ... | ... | @@ -8427,6 +8417,16 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8427 | 8417 | } |
| 8428 | 8418 | } |
| 8429 | 8419 | |
| 8420 | if (prev_type->id == TypeTableEntryIdNullLit) { |
| 8421 | prev_inst = cur_inst; |
| 8422 | continue; |
| 8423 | } |
| 8424 | |
| 8425 | if (cur_type->id == TypeTableEntryIdNullLit) { |
| 8426 | any_are_null = true; |
| 8427 | continue; |
| 8428 | } |
| 8429 | |
| 8430 | 8430 | if (types_match_const_cast_only(ira, prev_type, cur_type, source_node).id == ConstCastResultIdOk) { |
| 8431 | 8431 | continue; |
| 8432 | 8432 | } |
| ... | ... | @@ -8610,6 +8610,10 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8610 | 8610 | } else if (err_set_type != nullptr) { |
| 8611 | 8611 | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { |
| 8612 | 8612 | return err_set_type; |
| 8613 | } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) { |
| 8614 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type); |
| 8615 | } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) { |
| 8616 | return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); |
| 8613 | 8617 | } else { |
| 8614 | 8618 | if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt || |
| 8615 | 8619 | prev_inst->value.type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8621,8 +8625,6 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8621 | 8625 | ir_add_error_node(ira, source_node, |
| 8622 | 8626 | buf_sprintf("unable to make error union out of null literal")); |
| 8623 | 8627 | return ira->codegen->builtin_types.entry_invalid; |
| 8624 | | } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) { |
| 8625 | | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type); |
| 8626 | 8628 | } else { |
| 8627 | 8629 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); |
| 8628 | 8630 | } |
| ... | ... | @@ -10645,7 +10647,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 10645 | 10647 | } |
| 10646 | 10648 | |
| 10647 | 10649 | IrInstruction *instructions[] = {op1, op2}; |
| 10648 | | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, instructions, 2); |
| 10650 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 10649 | 10651 | if (type_is_invalid(resolved_type)) |
| 10650 | 10652 | return resolved_type; |
| 10651 | 10653 | type_ensure_zero_bits_known(ira->codegen, resolved_type); |
| ... | ... | @@ -11035,7 +11037,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 11035 | 11037 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11036 | 11038 | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 11037 | 11039 | IrInstruction *instructions[] = {op1, op2}; |
| 11038 | | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2); |
| 11040 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); |
| 11039 | 11041 | if (type_is_invalid(resolved_type)) |
| 11040 | 11042 | return resolved_type; |
| 11041 | 11043 | IrBinOp op_id = bin_op_instruction->op_id; |
| ... | ... | @@ -13004,7 +13006,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13004 | 13006 | return first_value->value.type; |
| 13005 | 13007 | } |
| 13006 | 13008 | |
| 13007 | | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, |
| 13009 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 13008 | 13010 | new_incoming_values.items, new_incoming_values.length); |
| 13009 | 13011 | if (type_is_invalid(resolved_type)) |
| 13010 | 13012 | return resolved_type; |
| ... | ... | @@ -18696,7 +18698,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 18696 | 18698 | } else if (ira->src_implicit_return_type_list.length == 0) { |
| 18697 | 18699 | return codegen->builtin_types.entry_unreachable; |
| 18698 | 18700 | } else { |
| 18699 | | return ir_resolve_peer_types(ira, expected_type_source_node, ira->src_implicit_return_type_list.items, |
| 18701 | return ir_resolve_peer_types(ira, expected_type_source_node, expected_type, ira->src_implicit_return_type_list.items, |
| 18700 | 18702 | ira->src_implicit_return_type_list.length); |
| 18701 | 18703 | } |
| 18702 | 18704 | } |