From 861b784454aa2ed3365b31dc18f9f569bc637703 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 29 Aug 2021 13:43:03 -0700 Subject: [PATCH] AstGen: fix incorrectly using decl_val/decl_ref in identifiers rather than directly referencing the instructions. --- src/AstGen.zig | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 59a2bc2de2..a51dd38f8c 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -6372,11 +6372,9 @@ fn identifier( if (local_val.name == name_str_index) { local_val.used = true; - // Captures of non-locals need to be emitted as decl_val or decl_ref. - // This *might* be capturable depending on if it is comptime known. - if (hit_namespace == 0) { - return rvalue(gz, rl, local_val.inst, ident); - } + // Locals cannot shadow anything, so we do not need to look for ambiguous + // references in this case. + return rvalue(gz, rl, local_val.inst, ident); } s = local_val.parent; }, @@ -6384,14 +6382,11 @@ fn identifier( const local_ptr = s.cast(Scope.LocalPtr).?; if (local_ptr.name == name_str_index) { local_ptr.used = true; - if (hit_namespace != 0) { - if (local_ptr.maybe_comptime) - break - else - return astgen.failNodeNotes(ident, "mutable '{s}' not accessible from here", .{ident_name}, &.{ - try astgen.errNoteTok(local_ptr.token_src, "declared mutable here", .{}), - try astgen.errNoteNode(hit_namespace, "crosses namespace boundary here", .{}), - }); + if (hit_namespace != 0 and !local_ptr.maybe_comptime) { + return astgen.failNodeNotes(ident, "mutable '{s}' not accessible from here", .{ident_name}, &.{ + try astgen.errNoteTok(local_ptr.token_src, "declared mutable here", .{}), + try astgen.errNoteNode(hit_namespace, "crosses namespace boundary here", .{}), + }); } switch (rl) { .ref, .none_or_ref => return local_ptr.ptr,