mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
AstGen: add error message for capture error by ref in switch on error
This commit is contained in:
parent
32e88251e4
commit
8b9425c248
@ -7219,7 +7219,9 @@ fn switchExprErrUnion(
|
||||
};
|
||||
|
||||
const capture_token = case.payload_token orelse break :blk &err_scope.base;
|
||||
assert(token_tags[capture_token] == .identifier);
|
||||
if (token_tags[capture_token] != .identifier) {
|
||||
return astgen.failTok(capture_token + 1, "error set cannot be captured by reference", .{});
|
||||
}
|
||||
|
||||
const capture_slice = tree.tokenSlice(capture_token);
|
||||
if (mem.eql(u8, capture_slice, "_")) {
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
export fn entry() void {
|
||||
const err: error{Foo} = error.Foo;
|
||||
|
||||
switch (err) {
|
||||
error.Foo => |*foo| {
|
||||
foo catch {};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :5:23: error: error set cannot be captured by reference
|
||||
@ -1,10 +1,8 @@
|
||||
export fn entry() void {
|
||||
const x: error{}!u32 = 0;
|
||||
if (x) |v| v else |_| switch (_) {
|
||||
}
|
||||
if (x) |v| v else |_| switch (_) {}
|
||||
}
|
||||
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
comptime {
|
||||
const e: error{Foo}!u32 = error.Foo;
|
||||
e catch |err| switch (err) {
|
||||
error.Foo => |*foo| {
|
||||
foo catch {};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
comptime {
|
||||
const e: error{Foo}!u32 = error.Foo;
|
||||
if (e) {} else |err| switch (err) {
|
||||
error.Foo => |*foo| {
|
||||
foo catch {};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :4:24: error: error set cannot be captured by reference
|
||||
// :13:24: error: error set cannot be captured by reference
|
||||
Loading…
x
Reference in New Issue
Block a user