Skip to content

Commit

Permalink
unescape identifier token when looking up symbol
Browse files Browse the repository at this point in the history
fixes #2132
  • Loading branch information
Techatrix committed Jan 9, 2025
1 parent f961c8b commit 6518f13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4089,8 +4089,8 @@ pub const DeclWithHandle = struct {
// TODO Peer type resolution, we just use the first resolvable item for now.
for (case.ast.values) |case_value| {
if (tree.nodes.items(.tag)[case_value] != .enum_literal) continue;

const name = tree.tokenSlice(tree.nodes.items(.main_token)[case_value]);
const name_token = tree.nodes.items(.main_token)[case_value];
const name = offsets.identifierTokenToNameSlice(tree, name_token);
const decl = try switch_expr_type.lookupSymbol(analyser, name) orelse continue;
break :blk (try decl.resolveType(analyser)) orelse continue;
}
Expand Down Expand Up @@ -4616,7 +4616,9 @@ pub fn resolveExpressionTypeFromAncestors(
var buffer: [2]Ast.Node.Index = undefined;
const struct_init = tree.fullStructInit(&buffer, ancestors[0]).?;
if (std.mem.indexOfScalar(Ast.Node.Index, struct_init.ast.fields, node) != null) {
const field_name = tree.tokenSlice(tree.firstToken(node) - 2);
const field_name_token = tree.firstToken(node) - 2;
if (token_tags[field_name_token] != .identifier) return null;
const field_name = offsets.identifierTokenToNameSlice(tree, field_name_token);
if (try analyser.lookupSymbolFieldInit(handle, field_name, ancestors)) |field_decl| {
return try field_decl.resolveType(analyser);
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/goto.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ fn gotoDefinitionLabel(
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

const name = offsets.locToSlice(handle.tree.source, loc);
const name_loc = Analyser.identifierLocFromIndex(handle.tree, pos_index) orelse return null;
const name = offsets.locToSlice(handle.tree.source, name_loc);
const decl = (try Analyser.lookupLabel(handle, name, pos_index)) orelse return null;
return try gotoDefinitionSymbol(analyser, offsets.locToRange(handle.tree.source, loc, offset_encoding), decl, kind, offset_encoding);
}
Expand Down

0 comments on commit 6518f13

Please sign in to comment.