Skip to content

Commit

Permalink
Partially fix bug in type resolution of paths
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-path.cc
	(TypeCheckExpr::resolve_root_path): Use segment node ids instead
	of the path node id to look up segment resolutions in the 2.0
	resolver, like is done with the 1.0 resolver, when possible.
	* typecheck/rust-hir-type-check-type.cc
	(TypeCheckType::resolve_root_path): Likewise, also remove
	unnecessary capture of path in lambda.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 committed Dec 1, 2024
1 parent 10cc6e8 commit 7713675
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 11 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,17 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

// assign the ref_node_id if we've found something
nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
.map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
ref_node_id = resolved;
});

// HACK: on failure, redo lookup using path node id
// This is incorrect, but will help some tests pass for now
// TODO: remove this
if (ref_node_id == UNKNOWN_NODEID)
nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
.map (
[&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
}
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
Expand Down
15 changes: 11 additions & 4 deletions gcc/rust/typecheck/rust-hir-type-check-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,17 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
// assign the ref_node_id if we've found something
nr_ctx.lookup (path.get_mappings ().get_nodeid ())
.map ([&ref_node_id, &path] (NodeId resolved) {
ref_node_id = resolved;
});
nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
ref_node_id = resolved;
});

// HACK: on failure, redo lookup using path node id
// This is incorrect, but will help some tests pass for now
// TODO: remove this
if (ref_node_id == UNKNOWN_NODEID)
nr_ctx.lookup (path.get_mappings ().get_nodeid ())
.map (
[&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
}
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
Expand Down

0 comments on commit 7713675

Please sign in to comment.