mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 04:25:05 +00:00
AstGen: fix catch payoad not checking for shadowing
This commit is contained in:
parent
c9006d9479
commit
81bbefe9b8
@ -4997,10 +4997,14 @@ fn orelseCatchExpr(
|
||||
var err_val_scope: Scope.LocalVal = undefined;
|
||||
const else_sub_scope = blk: {
|
||||
const payload = payload_token orelse break :blk &else_scope.base;
|
||||
if (mem.eql(u8, tree.tokenSlice(payload), "_")) {
|
||||
const err_str = tree.tokenSlice(payload);
|
||||
if (mem.eql(u8, err_str, "_")) {
|
||||
return astgen.failTok(payload, "discard of error capture; omit it instead", .{});
|
||||
}
|
||||
const err_name = try astgen.identAsString(payload);
|
||||
|
||||
try astgen.detectLocalShadowing(scope, err_name, payload, err_str);
|
||||
|
||||
err_val_scope = .{
|
||||
.parent = &else_scope.base,
|
||||
.gen_zir = &else_scope,
|
||||
|
||||
9
test/cases/variable_shadowing.10.zig
Normal file
9
test/cases/variable_shadowing.10.zig
Normal file
@ -0,0 +1,9 @@
|
||||
fn foo() !void {
|
||||
var i: anyerror!usize = 1;
|
||||
_ = i catch |i| return i;
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :3:18: error: redeclaration of local variable 'i'
|
||||
// :2:9: note: previous declaration here
|
||||
Loading…
x
Reference in New Issue
Block a user