diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 1658686acc..0acf9537ff 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -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, diff --git a/test/cases/compile_errors/switch_on_error_shadows_case_capture.zig b/test/cases/compile_errors/switch_on_error_shadows_case_capture.zig new file mode 100644 index 0000000000..d146be55ea --- /dev/null +++ b/test/cases/compile_errors/switch_on_error_shadows_case_capture.zig @@ -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