| author | |
| committer | |
| log | 097ca369d57a816512b726423ca97e07875a20c8 |
| tree | 3cd50d0370bfe1658e44fa052dc2929fb0691d8d |
| parent | 524345b6353c5aa4a848f4e579ab81f8ac126319 |
2 files changed, 25 insertions(+), 1 deletions(-)
lib/std/zig/AstGen.zig+1-1| ... | @@ -7693,7 +7693,7 @@ fn switchExpr( | ... | @@ -7693,7 +7693,7 @@ fn switchExpr( |
| 7693 | payload_sub_scope = switch_scope; | 7693 | payload_sub_scope = switch_scope; |
| 7694 | } else { | 7694 | } else { |
| 7695 | const capture_name = try astgen.identAsString(ident); | 7695 | const capture_name = try astgen.identAsString(ident); |
| 7696 | try astgen.detectLocalShadowing(&scratch_scope.base, capture_name, ident, ident_slice, .capture); | 7696 | try astgen.detectLocalShadowing(switch_scope, capture_name, ident, ident_slice, .capture); |
| 7697 | payload_capture_scope = .{ | 7697 | payload_capture_scope = .{ |
| 7698 | .parent = switch_scope, | 7698 | .parent = switch_scope, |
| 7699 | .gen_zir = &scratch_scope, | 7699 | .gen_zir = &scratch_scope, |
test/cases/compile_errors/switch_on_error_shadows_case_capture.zig created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | export fn entry1() void { | ||
| 2 | const e: error{Foo}!u32 = error.Foo; | ||
| 3 | e catch |err| switch (err) { | ||
| 4 | error.Foo => |err| { | ||
| 5 | _ = err catch {}; | ||
| 6 | }, | ||
| 7 | }; | ||
| 8 | } | ||
| 9 | |||
| 10 | export fn entry2() void { | ||
| 11 | const e: error{Foo}!u32 = error.Foo; | ||
| 12 | if (e) {} else |err| switch (err) { | ||
| 13 | error.Foo => |err| { | ||
| 14 | _ = err catch {}; | ||
| 15 | }, | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | // error | ||
| 20 | // | ||
| 21 | // :4:23: error: redeclaration of capture 'err' | ||
| 22 | // :3:14: note: previous declaration here | ||
| 23 | // :13:23: error: redeclaration of capture 'err' | ||
| 24 | // :12:21: note: previous declaration here | ||