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(...@@ -3182,10 +3182,12 @@ fn ensureResultUsed(
3182 const zcu = pt.zcu;3182 const zcu = pt.zcu;
3183 switch (ty.zigTypeTag(zcu)) {3183 switch (ty.zigTypeTag(zcu)) {
3184 .void, .noreturn => return,3184 .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 },
3186 .error_union => {3188 .error_union => {
3187 const msg = msg: {3189 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)});
3189 errdefer msg.destroy(sema.gpa);3191 errdefer msg.destroy(sema.gpa);
3190 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});3192 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
3191 break :msg msg;3193 break :msg msg;
test/cases/compile_errors/ignored_deferred_function_call.zig+2-2
...@@ -14,6 +14,6 @@ fn bar2() anyerror {...@@ -14,6 +14,6 @@ fn bar2() anyerror {
1414
15// error15// error
16//16//
17// :2:14: error: error union is ignored17// :2:14: error: error union of type 'anyerror!i32' is ignored
18// :2:14: note: consider using 'try', 'catch', or 'if'18// :2:14: note: consider using 'try', 'catch', or 'if'
19// :9:15: error: error set is ignored19// :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 {...@@ -24,10 +24,10 @@ fn bad2() anyerror {
2424
25// error25// error
26//26//
27// :2:24: error: error union is ignored27// :2:24: error: error union of type 'anyerror!void' is ignored
28// :2:24: note: consider using 'try', 'catch', or 'if'28// :2:24: note: consider using 'try', 'catch', or 'if'
29// :7:25: error: error union is ignored29// :7:25: error: error union of type 'anyerror!void' is ignored
30// :7:25: note: consider using 'try', 'catch', or 'if'30// :7:25: note: consider using 'try', 'catch', or 'if'
31// :12:25: error: error union is ignored31// :12:25: error: error union of type 'anyerror!void' is ignored
32// :12:25: note: consider using 'try', 'catch', or 'if'32// :12:25: note: consider using 'try', 'catch', or 'if'
33// :19:25: error: error set is ignored33// :19:25: error: error set of type 'anyerror' is ignored