| author | |
| committer | |
| log | 3f7b3daaa0a10cfe9eeeb42509abfbf851725741 |
| tree | 6dcebb29226148b1ee322ec086ef6ae713c92dcc |
| parent | 4a3800d78f8e341f90cfdd7f7038ed657952a9b1 |
4 files changed, 33 insertions(+), 18 deletions(-)
lib/std/zig/AstGen.zig+3-1| ... | ... | @@ -3172,7 +3172,8 @@ fn deferStmt( |
| 3172 | 3172 | const sub_scope = if (!have_err_code) &defer_gen.base else blk: { |
| 3173 | 3173 | const ident_name = try gz.astgen.identAsString(payload_token); |
| 3174 | 3174 | if (std.mem.eql(u8, tree.tokenSlice(payload_token), "_")) { |
| 3175 | return gz.astgen.failTok(payload_token, "discard of error capture; omit it instead", .{}); | |
| 3175 | try gz.astgen.appendErrorTok(payload_token, "discard of error capture; omit it instead", .{}); | |
| 3176 | break :blk &defer_gen.base; | |
| 3176 | 3177 | } |
| 3177 | 3178 | const remapped_err_code: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); |
| 3178 | 3179 | opt_remapped_err_code = remapped_err_code.toOptional(); |
| ... | ... | @@ -6219,6 +6220,7 @@ fn orelseCatchExpr( |
| 6219 | 6220 | const err_str = tree.tokenSlice(payload); |
| 6220 | 6221 | if (mem.eql(u8, err_str, "_")) { |
| 6221 | 6222 | try astgen.appendErrorTok(payload, "discard of error capture; omit it instead", .{}); |
| 6223 | break :blk &else_scope.base; | |
| 6222 | 6224 | } |
| 6223 | 6225 | const err_name = try astgen.identAsString(payload); |
| 6224 | 6226 |
test/cases/compile_errors/invalid_error_capture_discard.zig created+30| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | export fn a() void { | |
| 2 | errdefer |_| { | |
| 3 | @"_"; | |
| 4 | } | |
| 5 | } | |
| 6 | export fn b() void { | |
| 7 | const x: error{}!void = {}; | |
| 8 | x catch |_| { | |
| 9 | @"_"; | |
| 10 | }; | |
| 11 | } | |
| 12 | export fn c() void { | |
| 13 | const x: error{}!void = {}; | |
| 14 | x catch |_| switch (_) {}; | |
| 15 | } | |
| 16 | export fn d() void { | |
| 17 | const x: error{}!u32 = 0; | |
| 18 | if (x) |v| v else |_| switch (_) {} | |
| 19 | } | |
| 20 | ||
| 21 | // error | |
| 22 | // backend=stage2 | |
| 23 | // target=native | |
| 24 | // | |
| 25 | // :2:15: error: discard of error capture; omit it instead | |
| 26 | // :3:9: error: use of undeclared identifier '_' | |
| 27 | // :8:14: error: discard of error capture; omit it instead | |
| 28 | // :9:9: error: use of undeclared identifier '_' | |
| 29 | // :14:14: error: discard of error capture; omit it instead | |
| 30 | // :18:24: error: discard of error capture; omit it instead |
test/cases/compile_errors/switch_on_error_union_discard.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x: error{}!u32 = 0; | |
| 3 | if (x) |v| v else |_| switch (_) {} | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:24: error: discard of error capture; omit it instead |
test/cases/errdefer_discard.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | pub fn main() !void { | |
| 2 | errdefer |_| _ = @"_"; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // | |
| 7 | // :2:15: error: discard of error capture; omit it instead |