diff --git a/doc/langref.html.in b/doc/langref.html.in index a9281b4918..eef6e3e516 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3346,8 +3346,8 @@ fn deferErrorExample(is_error: bool) !void { } test "errdefer unwinding" { - _ = deferErrorExample(false); - _ = deferErrorExample(true); + deferErrorExample(false) catch {}; + deferErrorExample(true) catch {}; } {#code_end#} {#see_also|Errors#} diff --git a/src-self-hosted/codegen.zig b/src-self-hosted/codegen.zig index 1c671b61e2..90f5309faf 100644 --- a/src-self-hosted/codegen.zig +++ b/src-self-hosted/codegen.zig @@ -296,7 +296,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) if (!param.typ.handleIsPtr()) { //clear_debug_source_node(g); const llvm_param = llvm.GetParam(llvm_fn, @intCast(c_uint, i)); - _ = renderStoreUntyped( + _ = try renderStoreUntyped( ofile, llvm_param, scope_var.data.Param.llvm_value, diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index 069e182b3a..3f8c45aad7 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -1453,7 +1453,7 @@ pub const Builder = struct { child_scope = decl_var.params.variable.child_scope; } else if (!is_continuation_unreachable) { // this statement's value must be void - _ = irb.build( + _ = try irb.build( Inst.CheckVoidStmt, child_scope, Span{ @@ -1887,7 +1887,7 @@ pub const Builder = struct { } fn genAsyncReturn(irb: *Builder, scope: *Scope, span: Span, result: *Inst, is_gen: bool) !*Inst { - _ = irb.buildGen( + _ = try irb.buildGen( Inst.AddImplicitReturnType, scope, span, diff --git a/src/ir.cpp b/src/ir.cpp index 54b567efe5..62ac5ba970 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -13994,6 +13994,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source assert(ptr->value.type->id == ZigTypeIdPointer); if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { + if (uncasted_value->value.type->id == ZigTypeIdErrorUnion || + uncasted_value->value.type->id == ZigTypeIdErrorSet) + { + ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); + return ira->codegen->invalid_instruction; + } return ir_const_void(ira, source_instr); } diff --git a/std/build.zig b/std/build.zig index 0f88d09c2a..6409d625d8 100644 --- a/std/build.zig +++ b/std/build.zig @@ -282,7 +282,7 @@ pub const Builder = struct { if (self.verbose) { warn("rm {}\n", installed_file); } - _ = os.deleteFile(installed_file); + os.deleteFile(installed_file) catch {}; } // TODO remove empty directories diff --git a/std/os.zig b/std/os.zig index cbbc80c47d..7773976de5 100644 --- a/std/os.zig +++ b/std/os.zig @@ -807,7 +807,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned return switch (err) { windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound, else => { - _ = unexpectedErrorWindows(err); + unexpectedErrorWindows(err) catch {}; return error.EnvironmentVariableNotFound; }, }; @@ -877,9 +877,9 @@ pub fn getCwd(out_buffer: *[MAX_PATH_BYTES]u8) GetCwdError![]u8 { test "os.getCwd" { // at least call it so it gets compiled - _ = getCwdAlloc(debug.global_allocator); + _ = getCwdAlloc(debug.global_allocator) catch undefined; var buf: [MAX_PATH_BYTES]u8 = undefined; - _ = getCwd(&buf); + _ = getCwd(&buf) catch undefined; } pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError; diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 38b3c8af80..3269e39c7a 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -802,7 +802,7 @@ fn destroyPipe(pipe: [2]i32) void { // Child of fork calls this to report an error to the fork parent. // Then the child exits. fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { - _ = writeIntFd(fd, ErrInt(@errorToInt(err))); + writeIntFd(fd, ErrInt(@errorToInt(err))) catch {}; posix.exit(1); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e1e3f715c2..57e2504e5e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "discarding error value", + \\export fn entry() void { + \\ _ = foo(); + \\} + \\fn foo() !void { + \\ return error.OutOfMemory; + \\} + , + "tmp.zig:2:7: error: error is discarded", + ); + cases.add( "volatile on global assembly", \\comptime { diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index 0427efabd5..2d153ccff0 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ @import("std").os.exit(126); \\} \\pub fn main() void { - \\ _ = bar(9999); + \\ bar(9999) catch {}; \\} \\fn bar(x: u16) anyerror { \\ return @intToError(x); @@ -384,7 +384,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const Set1 = error{A, B}; \\const Set2 = error{A, C}; \\pub fn main() void { - \\ _ = foo(Set1.B); + \\ foo(Set1.B) catch {}; \\} \\fn foo(set1: Set1) Set2 { \\ return @errSetCast(Set2, set1); diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig index 7d9dae7bdd..babefba6f5 100644 --- a/test/stage1/behavior/error.zig +++ b/test/stage1/behavior/error.zig @@ -205,8 +205,8 @@ fn foo2(f: fn () anyerror!void) void { fn bar2() (error{}!void) {} test "error: Zero sized error set returned with value payload crash" { - _ = foo3(0); - _ = comptime foo3(0); + _ = foo3(0) catch {}; + _ = comptime foo3(0) catch {}; } const Error = error{};