| author | |
| committer | |
| log | 64dddd7afe14a683826b03bc36ab80fa93a84e2c |
| tree | 1c8770889f7ce5cec39f193a5899eaf3a044df0b |
| parent | 6a9c32f7597d37592d79afa27441e7caf9a30529 |
| signature |
closes #77210 files changed, 32 insertions(+), 14 deletions(-)
doc/langref.html.in+2-2| ... | @@ -3346,8 +3346,8 @@ fn deferErrorExample(is_error: bool) !void { | ... | @@ -3346,8 +3346,8 @@ fn deferErrorExample(is_error: bool) !void { |
| 3346 | } | 3346 | } |
| 3347 | 3347 | ||
| 3348 | test "errdefer unwinding" { | 3348 | test "errdefer unwinding" { |
| 3349 | _ = deferErrorExample(false); | 3349 | deferErrorExample(false) catch {}; |
| 3350 | _ = deferErrorExample(true); | 3350 | deferErrorExample(true) catch {}; |
| 3351 | } | 3351 | } |
| 3352 | {#code_end#} | 3352 | {#code_end#} |
| 3353 | {#see_also|Errors#} | 3353 | {#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) | ... | @@ -296,7 +296,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 296 | if (!param.typ.handleIsPtr()) { | 296 | if (!param.typ.handleIsPtr()) { |
| 297 | //clear_debug_source_node(g); | 297 | //clear_debug_source_node(g); |
| 298 | const llvm_param = llvm.GetParam(llvm_fn, @intCast(c_uint, i)); | 298 | const llvm_param = llvm.GetParam(llvm_fn, @intCast(c_uint, i)); |
| 299 | _ = renderStoreUntyped( | 299 | _ = try renderStoreUntyped( |
| 300 | ofile, | 300 | ofile, |
| 301 | llvm_param, | 301 | llvm_param, |
| 302 | scope_var.data.Param.llvm_value, | 302 | scope_var.data.Param.llvm_value, |
src-self-hosted/ir.zig+2-2| ... | @@ -1453,7 +1453,7 @@ pub const Builder = struct { | ... | @@ -1453,7 +1453,7 @@ pub const Builder = struct { |
| 1453 | child_scope = decl_var.params.variable.child_scope; | 1453 | child_scope = decl_var.params.variable.child_scope; |
| 1454 | } else if (!is_continuation_unreachable) { | 1454 | } else if (!is_continuation_unreachable) { |
| 1455 | // this statement's value must be void | 1455 | // this statement's value must be void |
| 1456 | _ = irb.build( | 1456 | _ = try irb.build( |
| 1457 | Inst.CheckVoidStmt, | 1457 | Inst.CheckVoidStmt, |
| 1458 | child_scope, | 1458 | child_scope, |
| 1459 | Span{ | 1459 | Span{ |
| ... | @@ -1887,7 +1887,7 @@ pub const Builder = struct { | ... | @@ -1887,7 +1887,7 @@ pub const Builder = struct { |
| 1887 | } | 1887 | } |
| 1888 | 1888 | ||
| 1889 | fn genAsyncReturn(irb: *Builder, scope: *Scope, span: Span, result: *Inst, is_gen: bool) !*Inst { | 1889 | fn genAsyncReturn(irb: *Builder, scope: *Scope, span: Span, result: *Inst, is_gen: bool) !*Inst { |
| 1890 | _ = irb.buildGen( | 1890 | _ = try irb.buildGen( |
| 1891 | Inst.AddImplicitReturnType, | 1891 | Inst.AddImplicitReturnType, |
| 1892 | scope, | 1892 | scope, |
| 1893 | span, | 1893 | span, |
src/ir.cpp+6| ... | @@ -13994,6 +13994,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -13994,6 +13994,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 13994 | assert(ptr->value.type->id == ZigTypeIdPointer); | 13994 | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 13995 | 13995 | ||
| 13996 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { | 13996 | 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 | } | ||
| 13997 | return ir_const_void(ira, source_instr); | 14003 | return ir_const_void(ira, source_instr); |
| 13998 | } | 14004 | } |
| 13999 | 14005 |
std/build.zig+1-1| ... | @@ -282,7 +282,7 @@ pub const Builder = struct { | ... | @@ -282,7 +282,7 @@ pub const Builder = struct { |
| 282 | if (self.verbose) { | 282 | if (self.verbose) { |
| 283 | warn("rm {}\n", installed_file); | 283 | warn("rm {}\n", installed_file); |
| 284 | } | 284 | } |
| 285 | _ = os.deleteFile(installed_file); | 285 | os.deleteFile(installed_file) catch {}; |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | // TODO remove empty directories | 288 | // TODO remove empty directories |
std/os.zig+3-3| ... | @@ -807,7 +807,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned | ... | @@ -807,7 +807,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned |
| 807 | return switch (err) { | 807 | return switch (err) { |
| 808 | windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound, | 808 | windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound, |
| 809 | else => { | 809 | else => { |
| 810 | _ = unexpectedErrorWindows(err); | 810 | unexpectedErrorWindows(err) catch {}; |
| 811 | return error.EnvironmentVariableNotFound; | 811 | return error.EnvironmentVariableNotFound; |
| 812 | }, | 812 | }, |
| 813 | }; | 813 | }; |
| ... | @@ -877,9 +877,9 @@ pub fn getCwd(out_buffer: *[MAX_PATH_BYTES]u8) GetCwdError![]u8 { | ... | @@ -877,9 +877,9 @@ pub fn getCwd(out_buffer: *[MAX_PATH_BYTES]u8) GetCwdError![]u8 { |
| 877 | 877 | ||
| 878 | test "os.getCwd" { | 878 | test "os.getCwd" { |
| 879 | // at least call it so it gets compiled | 879 | // at least call it so it gets compiled |
| 880 | _ = getCwdAlloc(debug.global_allocator); | 880 | _ = getCwdAlloc(debug.global_allocator) catch undefined; |
| 881 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 881 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 882 | _ = getCwd(&buf); | 882 | _ = getCwd(&buf) catch undefined; |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError; | 885 | pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError; |
std/os/child_process.zig+1-1| ... | @@ -802,7 +802,7 @@ fn destroyPipe(pipe: [2]i32) void { | ... | @@ -802,7 +802,7 @@ fn destroyPipe(pipe: [2]i32) void { |
| 802 | // Child of fork calls this to report an error to the fork parent. | 802 | // Child of fork calls this to report an error to the fork parent. |
| 803 | // Then the child exits. | 803 | // Then the child exits. |
| 804 | fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { | 804 | fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 805 | _ = writeIntFd(fd, ErrInt(@errorToInt(err))); | 805 | writeIntFd(fd, ErrInt(@errorToInt(err))) catch {}; |
| 806 | posix.exit(1); | 806 | posix.exit(1); |
| 807 | } | 807 | } |
| 808 | 808 |
test/compile_errors.zig+12| ... | @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,18 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub 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 | |||
| 5 | cases.add( | 17 | cases.add( |
| 6 | "volatile on global assembly", | 18 | "volatile on global assembly", |
| 7 | \\comptime { | 19 | \\comptime { |
test/runtime_safety.zig+2-2| ... | @@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 370 | \\ @import("std").os.exit(126); | 370 | \\ @import("std").os.exit(126); |
| 371 | \\} | 371 | \\} |
| 372 | \\pub fn main() void { | 372 | \\pub fn main() void { |
| 373 | \\ _ = bar(9999); | 373 | \\ bar(9999) catch {}; |
| 374 | \\} | 374 | \\} |
| 375 | \\fn bar(x: u16) anyerror { | 375 | \\fn bar(x: u16) anyerror { |
| 376 | \\ return @intToError(x); | 376 | \\ return @intToError(x); |
| ... | @@ -384,7 +384,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -384,7 +384,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 384 | \\const Set1 = error{A, B}; | 384 | \\const Set1 = error{A, B}; |
| 385 | \\const Set2 = error{A, C}; | 385 | \\const Set2 = error{A, C}; |
| 386 | \\pub fn main() void { | 386 | \\pub fn main() void { |
| 387 | \\ _ = foo(Set1.B); | 387 | \\ foo(Set1.B) catch {}; |
| 388 | \\} | 388 | \\} |
| 389 | \\fn foo(set1: Set1) Set2 { | 389 | \\fn foo(set1: Set1) Set2 { |
| 390 | \\ return @errSetCast(Set2, set1); | 390 | \\ return @errSetCast(Set2, set1); |
test/stage1/behavior/error.zig+2-2| ... | @@ -205,8 +205,8 @@ fn foo2(f: fn () anyerror!void) void { | ... | @@ -205,8 +205,8 @@ fn foo2(f: fn () anyerror!void) void { |
| 205 | fn bar2() (error{}!void) {} | 205 | fn bar2() (error{}!void) {} |
| 206 | 206 | ||
| 207 | test "error: Zero sized error set returned with value payload crash" { | 207 | test "error: Zero sized error set returned with value payload crash" { |
| 208 | _ = foo3(0); | 208 | _ = foo3(0) catch {}; |
| 209 | _ = comptime foo3(0); | 209 | _ = comptime foo3(0) catch {}; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | const Error = error{}; | 212 | const Error = error{}; |