Files
zig/test/cases/compile_errors/discarding_error_value.zig
r00ster91 9ae43567a3 Sema: improve error set/union discard/ignore errors
Previously the error had a note suggesting to use `try`, `catch`, or
`if`, even for error sets where none of those work.
Instead, in case of an error set the way you can handle the error
depends very much on the specific case. For example you might be in a
`catch` where you are discarding or ignoring the error set capture
value, in which case one way to handle the error might be to `return`
the error.
So, in that case, we do not attach that error note.

Additionally, this makes the error tell you what kind of an error it is:
is it an error set or an error union? This distinction is very relevant
in how to handle the error.
2024-05-14 01:13:49 +09:00

19 lines
350 B
Zig

export fn entry1() void {
_ = foo();
}
fn foo() !void {
return error.OutOfMemory;
}
export fn entry2() void {
const x: error{a} = undefined;
_ = x;
}
// error
// backend=stage2
// target=native
//
// :2:12: error: error union is discarded
// :2:12: note: consider using 'try', 'catch', or 'if'
// :9:9: error: error set is discarded