| ... | @@ -20603,17 +20603,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -20603,17 +20603,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20603 | return ira->codegen->invalid_inst_gen; | 20603 | return ira->codegen->invalid_inst_gen; |
| 20604 | } | 20604 | } |
| 20605 | | 20605 | |
| | 20606 | ZigType *expected_return_type = result_loc->value->type->data.pointer.child_type; |
| | 20607 | |
| 20606 | IrInstGen *dummy_value = ir_const(ira, source_instr, return_type); | 20608 | IrInstGen *dummy_value = ir_const(ira, source_instr, return_type); |
| 20607 | dummy_value->value->special = ConstValSpecialRuntime; | 20609 | dummy_value->value->special = ConstValSpecialRuntime; |
| 20608 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, | 20610 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, |
| 20609 | dummy_value, result_loc->value->type->data.pointer.child_type); | 20611 | dummy_value, expected_return_type); |
| 20610 | if (type_is_invalid(dummy_result->value->type)) | 20612 | if (type_is_invalid(dummy_result->value->type)) { |
| | 20613 | if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) && |
| | 20614 | expected_return_type->id != ZigTypeIdErrorUnion && expected_return_type->id != ZigTypeIdErrorSet) |
| | 20615 | { |
| | 20616 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, |
| | 20617 | ira->explicit_return_type_source_node, buf_create_from_str("function cannot return an error")); |
| | 20618 | } |
| 20611 | return ira->codegen->invalid_inst_gen; | 20619 | return ira->codegen->invalid_inst_gen; |
| 20612 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; | | |
| 20613 | if (res_child_type == ira->codegen->builtin_types.entry_anytype) { | | |
| 20614 | res_child_type = return_type; | | |
| 20615 | } | 20620 | } |
| 20616 | if (!handle_is_ptr(ira->codegen, res_child_type)) { | 20621 | if (expected_return_type == ira->codegen->builtin_types.entry_anytype) { |
| | 20622 | expected_return_type = return_type; |
| | 20623 | } |
| | 20624 | if (!handle_is_ptr(ira->codegen, expected_return_type)) { |
| 20617 | ir_reset_result(call_result_loc); | 20625 | ir_reset_result(call_result_loc); |
| 20618 | result_loc = nullptr; | 20626 | result_loc = nullptr; |
| 20619 | } | 20627 | } |
| ... | @@ -30907,6 +30915,13 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx | ... | @@ -30907,6 +30915,13 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx |
| 30907 | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value, | 30915 | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value, |
| 30908 | instruction->result_loc->allow_write_through_const); | 30916 | instruction->result_loc->allow_write_through_const); |
| 30909 | if (type_is_invalid(store_ptr->value->type)) { | 30917 | if (type_is_invalid(store_ptr->value->type)) { |
| | 30918 | if (instruction->result_loc->id == ResultLocIdReturn && |
| | 30919 | (value->value->type->id == ZigTypeIdErrorUnion || value->value->type->id == ZigTypeIdErrorSet) && |
| | 30920 | ira->explicit_return_type->id != ZigTypeIdErrorUnion && ira->explicit_return_type->id != ZigTypeIdErrorSet) |
| | 30921 | { |
| | 30922 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, |
| | 30923 | ira->explicit_return_type_source_node, buf_create_from_str("function cannot return an error")); |
| | 30924 | } |
| 30910 | return ira->codegen->invalid_inst_gen; | 30925 | return ira->codegen->invalid_inst_gen; |
| 30911 | } | 30926 | } |
| 30912 | } | 30927 | } |