authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-19 18:27:58-07:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-02 12:18:32+02:00
log9bc98f5911dd30ce4f0b62c6cc5eaaeb6d6b5e2d
treeb68a94924f093adf6bd5136b290c64f912e82b95
parent407061498ce1d23ec498cce234433d18668d46be

sema: improve ignored error value compile error message


3 files changed, 10 insertions(+), 8 deletions(-)

src/Sema.zig+4-2
......@@ -3182,10 +3182,12 @@ fn ensureResultUsed(
31823182 const zcu = pt.zcu;
31833183 switch (ty.zigTypeTag(zcu)) {
31843184 .void, .noreturn => return,
3185 .error_set => return sema.fail(block, src, "error set is ignored", .{}),
3185 .error_set => {
3186 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(pt)});
3187 },
31863188 .error_union => {
31873189 const msg = msg: {
3188 const msg = try sema.errMsg(src, "error union is ignored", .{});
3190 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(pt)});
31893191 errdefer msg.destroy(sema.gpa);
31903192 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
31913193 break :msg msg;
test/cases/compile_errors/ignored_deferred_function_call.zig+2-2
......@@ -14,6 +14,6 @@ fn bar2() anyerror {
1414
1515// error
1616//
17// :2:14: error: error union is ignored
17// :2:14: error: error union of type 'anyerror!i32' is ignored
1818// :2:14: note: consider using 'try', 'catch', or 'if'
19// :9:15: error: error set is ignored
19// :9:15: error: error set of type 'anyerror' is ignored
test/cases/compile_errors/ignored_expression_in_while_continuation.zig+4-4
......@@ -24,10 +24,10 @@ fn bad2() anyerror {
2424
2525// error
2626//
27// :2:24: error: error union is ignored
27// :2:24: error: error union of type 'anyerror!void' is ignored
2828// :2:24: note: consider using 'try', 'catch', or 'if'
29// :7:25: error: error union is ignored
29// :7:25: error: error union of type 'anyerror!void' is ignored
3030// :7:25: note: consider using 'try', 'catch', or 'if'
31// :12:25: error: error union is ignored
31// :12:25: error: error union of type 'anyerror!void' is ignored
3232// :12:25: note: consider using 'try', 'catch', or 'if'
33// :19:25: error: error set is ignored
33// :19:25: error: error set of type 'anyerror' is ignored