authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-24 15:24:00+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-24 15:24:00+03:00
logc1ee9efb7c2a1589b14d6efeffb1f5e6c2d9b994
treedd65470c97d824bc6a6553d3f8eb5f917df17e5a
parent9589dc4c954c1fd10bdf075c62418aeed42ae96f
signaturelock-open Commit is signed but in an unrecognized format.

fix error note using invalid source node

Closes #6153

2 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,
2069520695 if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) &&
2069620696 expected_return_type->id != ZigTypeIdErrorUnion && expected_return_type->id != ZigTypeIdErrorSet)
2069720697 {
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 }
2070020705 }
2070120706 return ira->codegen->invalid_inst_gen;
2070220707 }
test/compile_errors.zig+8-2
......@@ -158,16 +158,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
158158 \\export fn baz() void {
159159 \\ try bar();
160160 \\}
161 \\export fn quux() u32 {
161 \\export fn qux() u32 {
162162 \\ return bar();
163163 \\}
164 \\export fn quux() u32 {
165 \\ var buf: u32 = 0;
166 \\ buf = bar();
167 \\}
164168 , &[_][]const u8{
165169 "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'",
166170 "tmp.zig:1:17: note: function cannot return an error",
167171 "tmp.zig:8:5: error: expected type 'void', found '@TypeOf(bar).ReturnType.ErrorSet'",
168172 "tmp.zig:7:17: note: function cannot return an error",
169173 "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'",
171177 });
172178
173179 cases.addTest("int/float conversion to comptime_int/float",