authorgravatar for 39064859+ieeemma@users.noreply.github.comemma <39064859+ieeemma@users.noreply.github.com> 2022-07-07 19:38:32+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-07 21:38:32+03:00
log81bbefe9b837dc439a68458ca91d522c1c49b96b
tree796fd5138faa9b6312e5464ecd9266db5339f079
parentc9006d9479c619d9ed555164831e11a04d88d382
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

AstGen: fix catch payoad not checking for shadowing


2 files changed, 14 insertions(+), 1 deletions(-)

src/AstGen.zig+5-1
...@@ -4997,10 +4997,14 @@ fn orelseCatchExpr(...@@ -4997,10 +4997,14 @@ fn orelseCatchExpr(
4997 var err_val_scope: Scope.LocalVal = undefined;4997 var err_val_scope: Scope.LocalVal = undefined;
4998 const else_sub_scope = blk: {4998 const else_sub_scope = blk: {
4999 const payload = payload_token orelse break :blk &else_scope.base;4999 const payload = payload_token orelse break :blk &else_scope.base;
5000 if (mem.eql(u8, tree.tokenSlice(payload), "_")) {5000 const err_str = tree.tokenSlice(payload);
5001 if (mem.eql(u8, err_str, "_")) {
5001 return astgen.failTok(payload, "discard of error capture; omit it instead", .{});5002 return astgen.failTok(payload, "discard of error capture; omit it instead", .{});
5002 }5003 }
5003 const err_name = try astgen.identAsString(payload);5004 const err_name = try astgen.identAsString(payload);
5005
5006 try astgen.detectLocalShadowing(scope, err_name, payload, err_str);
5007
5004 err_val_scope = .{5008 err_val_scope = .{
5005 .parent = &else_scope.base,5009 .parent = &else_scope.base,
5006 .gen_zir = &else_scope,5010 .gen_zir = &else_scope,
test/cases/variable_shadowing.10.zig created+9
...@@ -0,0 +1,9 @@
1fn foo() !void {
2 var i: anyerror!usize = 1;
3 _ = i catch |i| return i;
4}
5
6// error
7//
8// :3:18: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here