diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-16 16:55:49 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-16 20:35:03 +0300 |
| commit | 9d4561ef0082728bbba085e8a4689ccc93a37b27 (patch) | |
| tree | 8bb2dd3845b94629b49c0a778999d9dcdf2a9f47 /src | |
| parent | c17793b4875cc9e1ccb605431142ffecb0b6f3f2 (diff) | |
| download | zig-9d4561ef0082728bbba085e8a4689ccc93a37b27.tar.gz zig-9d4561ef0082728bbba085e8a4689ccc93a37b27.zip | |
AstGen: detect declarations shadowing locals
Closes #9355
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 1151ed60da..2fcd8cd994 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -11751,6 +11751,46 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast. error.OutOfMemory => return error.OutOfMemory, } } + + // const index_name = try astgen.identAsString(index_token); + var s = namespace.parent; + while (true) switch (s.tag) { + .local_val => { + const local_val = s.cast(Scope.LocalVal).?; + if (local_val.name == name_str_index) { + return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{ + @tagName(local_val.id_cat), token_bytes, + }, &[_]u32{ + try astgen.errNoteTok( + local_val.token_src, + "previous declaration here", + .{}, + ), + }); + } + s = local_val.parent; + }, + .local_ptr => { + const local_ptr = s.cast(Scope.LocalPtr).?; + if (local_ptr.name == name_str_index) { + return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{ + @tagName(local_ptr.id_cat), token_bytes, + }, &[_]u32{ + try astgen.errNoteTok( + local_ptr.token_src, + "previous declaration here", + .{}, + ), + }); + } + s = local_ptr.parent; + }, + .namespace => s = s.cast(Scope.Namespace).?.parent, + .gen_zir => s = s.cast(GenZir).?.parent, + .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, + .defer_gen => s = s.cast(Scope.DeferGen).?.parent, + .top => break, + }; gop.value_ptr.* = member_node; } return decl_count; |
