detect when switch on error shadows it's own switch case capture

This commit is contained in:
Techatrix
2026-03-13 14:11:00 +01:00
committed by Andrew Kelley
parent 524345b635
commit 097ca369d5
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -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