mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
detect when switch on error shadows it's own switch case capture
This commit is contained in:
@@ -7693,7 +7693,7 @@ fn switchExpr(
|
||||
payload_sub_scope = switch_scope;
|
||||
} else {
|
||||
const capture_name = try astgen.identAsString(ident);
|
||||
try astgen.detectLocalShadowing(&scratch_scope.base, capture_name, ident, ident_slice, .capture);
|
||||
try astgen.detectLocalShadowing(switch_scope, capture_name, ident, ident_slice, .capture);
|
||||
payload_capture_scope = .{
|
||||
.parent = switch_scope,
|
||||
.gen_zir = &scratch_scope,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export fn entry1() void {
|
||||
const e: error{Foo}!u32 = error.Foo;
|
||||
e catch |err| switch (err) {
|
||||
error.Foo => |err| {
|
||||
_ = err catch {};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export fn entry2() void {
|
||||
const e: error{Foo}!u32 = error.Foo;
|
||||
if (e) {} else |err| switch (err) {
|
||||
error.Foo => |err| {
|
||||
_ = err catch {};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :4:23: error: redeclaration of capture 'err'
|
||||
// :3:14: note: previous declaration here
|
||||
// :13:23: error: redeclaration of capture 'err'
|
||||
// :12:21: note: previous declaration here
|
||||
Reference in New Issue
Block a user