authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-23 19:33:00-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-23 19:33:00-04:00
log64dddd7afe14a683826b03bc36ab80fa93a84e2c
tree1c8770889f7ce5cec39f193a5899eaf3a044df0b
parent6a9c32f7597d37592d79afa27441e7caf9a30529
signaturelock-open Commit is signed but in an unrecognized format.

add compile error for ignoring error

closes #772

10 files changed, 32 insertions(+), 14 deletions(-)

doc/langref.html.in+2-2
......@@ -3346,8 +3346,8 @@ fn deferErrorExample(is_error: bool) !void {
33463346}
33473347
33483348test "errdefer unwinding" {
3349 _ = deferErrorExample(false);
3350 _ = deferErrorExample(true);
3349 deferErrorExample(false) catch {};
3350 deferErrorExample(true) catch {};
33513351}
33523352 {#code_end#}
33533353 {#see_also|Errors#}
src-self-hosted/codegen.zig+1-1
......@@ -296,7 +296,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
296296 if (!param.typ.handleIsPtr()) {
297297 //clear_debug_source_node(g);
298298 const llvm_param = llvm.GetParam(llvm_fn, @intCast(c_uint, i));
299 _ = renderStoreUntyped(
299 _ = try renderStoreUntyped(
300300 ofile,
301301 llvm_param,
302302 scope_var.data.Param.llvm_value,
src-self-hosted/ir.zig+2-2
......@@ -1453,7 +1453,7 @@ pub const Builder = struct {
14531453 child_scope = decl_var.params.variable.child_scope;
14541454 } else if (!is_continuation_unreachable) {
14551455 // this statement's value must be void
1456 _ = irb.build(
1456 _ = try irb.build(
14571457 Inst.CheckVoidStmt,
14581458 child_scope,
14591459 Span{
......@@ -1887,7 +1887,7 @@ pub const Builder = struct {
18871887 }
18881888
18891889 fn genAsyncReturn(irb: *Builder, scope: *Scope, span: Span, result: *Inst, is_gen: bool) !*Inst {
1890 _ = irb.buildGen(
1890 _ = try irb.buildGen(
18911891 Inst.AddImplicitReturnType,
18921892 scope,
18931893 span,
src/ir.cpp+6
......@@ -13994,6 +13994,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1399413994 assert(ptr->value.type->id == ZigTypeIdPointer);
1399513995
1399613996 if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {
13997 if (uncasted_value->value.type->id == ZigTypeIdErrorUnion ||
13998 uncasted_value->value.type->id == ZigTypeIdErrorSet)
13999 {
14000 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
14001 return ira->codegen->invalid_instruction;
14002 }
1399714003 return ir_const_void(ira, source_instr);
1399814004 }
1399914005
std/build.zig+1-1
......@@ -282,7 +282,7 @@ pub const Builder = struct {
282282 if (self.verbose) {
283283 warn("rm {}\n", installed_file);
284284 }
285 _ = os.deleteFile(installed_file);
285 os.deleteFile(installed_file) catch {};
286286 }
287287
288288 // TODO remove empty directories
std/os.zig+3-3
......@@ -807,7 +807,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
807807 return switch (err) {
808808 windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound,
809809 else => {
810 _ = unexpectedErrorWindows(err);
810 unexpectedErrorWindows(err) catch {};
811811 return error.EnvironmentVariableNotFound;
812812 },
813813 };
......@@ -877,9 +877,9 @@ pub fn getCwd(out_buffer: *[MAX_PATH_BYTES]u8) GetCwdError![]u8 {
877877
878878test "os.getCwd" {
879879 // at least call it so it gets compiled
880 _ = getCwdAlloc(debug.global_allocator);
880 _ = getCwdAlloc(debug.global_allocator) catch undefined;
881881 var buf: [MAX_PATH_BYTES]u8 = undefined;
882 _ = getCwd(&buf);
882 _ = getCwd(&buf) catch undefined;
883883}
884884
885885pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError;
std/os/child_process.zig+1-1
......@@ -802,7 +802,7 @@ fn destroyPipe(pipe: [2]i32) void {
802802// Child of fork calls this to report an error to the fork parent.
803803// Then the child exits.
804804fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
805 _ = writeIntFd(fd, ErrInt(@errorToInt(err)));
805 writeIntFd(fd, ErrInt(@errorToInt(err))) catch {};
806806 posix.exit(1);
807807}
808808
test/compile_errors.zig+12
......@@ -2,6 +2,18 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "discarding error value",
7 \\export fn entry() void {
8 \\ _ = foo();
9 \\}
10 \\fn foo() !void {
11 \\ return error.OutOfMemory;
12 \\}
13 ,
14 "tmp.zig:2:7: error: error is discarded",
15 );
16
517 cases.add(
618 "volatile on global assembly",
719 \\comptime {
test/runtime_safety.zig+2-2
......@@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
370370 \\ @import("std").os.exit(126);
371371 \\}
372372 \\pub fn main() void {
373 \\ _ = bar(9999);
373 \\ bar(9999) catch {};
374374 \\}
375375 \\fn bar(x: u16) anyerror {
376376 \\ return @intToError(x);
......@@ -384,7 +384,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
384384 \\const Set1 = error{A, B};
385385 \\const Set2 = error{A, C};
386386 \\pub fn main() void {
387 \\ _ = foo(Set1.B);
387 \\ foo(Set1.B) catch {};
388388 \\}
389389 \\fn foo(set1: Set1) Set2 {
390390 \\ return @errSetCast(Set2, set1);
test/stage1/behavior/error.zig+2-2
......@@ -205,8 +205,8 @@ fn foo2(f: fn () anyerror!void) void {
205205fn bar2() (error{}!void) {}
206206
207207test "error: Zero sized error set returned with value payload crash" {
208 _ = foo3(0);
209 _ = comptime foo3(0);
208 _ = foo3(0) catch {};
209 _ = comptime foo3(0) catch {};
210210}
211211
212212const Error = error{};