From 77136751110b7e22039ea19227083aad64856971 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sat, 30 Nov 2024 19:28:49 -0500 Subject: [PATCH] Partially fix bug in type resolution of paths 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 --- gcc/rust/typecheck/rust-hir-type-check-path.cc | 13 +++++++++++-- gcc/rust/typecheck/rust-hir-type-check-type.cc | 15 +++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index d3f341264482..11f4884485f1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -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); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index aaff8db99bad..70fca868e976 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -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);