| author | |
| committer | |
| log | c1ee9efb7c2a1589b14d6efeffb1f5e6c2d9b994 |
| tree | dd65470c97d824bc6a6553d3f8eb5f917df17e5a |
| parent | 9589dc4c954c1fd10bdf075c62418aeed42ae96f |
| signature |
Closes #61532 files changed, 15 insertions(+), 4 deletions(-)
src/ir.cpp+7-2| ... | ... | @@ -20695,8 +20695,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20695 | 20695 | if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) && |
| 20696 | 20696 | expected_return_type->id != ZigTypeIdErrorUnion && expected_return_type->id != ZigTypeIdErrorSet) |
| 20697 | 20697 | { |
| 20698 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, | |
| 20699 | ira->explicit_return_type_source_node, buf_create_from_str("function cannot return an error")); | |
| 20698 | if (call_result_loc->id == ResultLocIdReturn) { | |
| 20699 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, | |
| 20700 | ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error")); | |
| 20701 | } else { | |
| 20702 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node, | |
| 20703 | buf_sprintf("cannot store an error in type '%s'", buf_ptr(&expected_return_type->name))); | |
| 20704 | } | |
| 20700 | 20705 | } |
| 20701 | 20706 | return ira->codegen->invalid_inst_gen; |
| 20702 | 20707 | } |
test/compile_errors.zig+8-2| ... | ... | @@ -158,16 +158,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 158 | 158 | \\export fn baz() void { |
| 159 | 159 | \\ try bar(); |
| 160 | 160 | \\} |
| 161 | \\export fn quux() u32 { | |
| 161 | \\export fn qux() u32 { | |
| 162 | 162 | \\ return bar(); |
| 163 | 163 | \\} |
| 164 | \\export fn quux() u32 { | |
| 165 | \\ var buf: u32 = 0; | |
| 166 | \\ buf = bar(); | |
| 167 | \\} | |
| 164 | 168 | , &[_][]const u8{ |
| 165 | 169 | "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'", |
| 166 | 170 | "tmp.zig:1:17: note: function cannot return an error", |
| 167 | 171 | "tmp.zig:8:5: error: expected type 'void', found '@TypeOf(bar).ReturnType.ErrorSet'", |
| 168 | 172 | "tmp.zig:7:17: note: function cannot return an error", |
| 169 | 173 | "tmp.zig:11:15: error: expected type 'u32', found '@TypeOf(bar).ReturnType.ErrorSet!u32'", |
| 170 | "tmp.zig:10:18: note: function cannot return an error", | |
| 174 | "tmp.zig:10:17: note: function cannot return an error", | |
| 175 | "tmp.zig:15:14: error: expected type 'u32', found '@TypeOf(bar).ReturnType.ErrorSet!u32'", | |
| 176 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", | |
| 171 | 177 | }); |
| 172 | 178 | |
| 173 | 179 | cases.addTest("int/float conversion to comptime_int/float", |