Skip to content

Commit

Permalink
name-resolver fix
Browse files Browse the repository at this point in the history
  • Loading branch information
philberty committed Jun 14, 2021
1 parent df36e6b commit f1c9aee
Showing 1 changed file with 58 additions and 54 deletions.
112 changes: 58 additions & 54 deletions gcc/rust/resolve/rust-ast-resolve.cc
Expand Up @@ -537,61 +537,65 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
AST::PathExprSegment &seg = expr->get_segments ().at (i);
auto s = ResolvePathSegmentToCanonicalPath::resolve (seg);
path = path.append (s);
}

if (resolver->get_name_scope ().lookup (path, &resolved_node))
{
resolver->insert_resolved_name (expr->get_node_id (), resolved_node);
resolver->insert_new_definition (expr->get_node_id (),
Definition{expr->get_node_id (),
parent});
}
// check the type scope
else if (resolver->get_type_scope ().lookup (path, &resolved_node))
{
resolver->insert_resolved_type (expr->get_node_id (), resolved_node);
resolver->insert_new_definition (expr->get_node_id (),
Definition{expr->get_node_id (),
parent});
}
else
{
// attempt to fully resolve the path which is allowed to fail given the
// following scenario
//
// https://github.com/Rust-GCC/gccrs/issues/355 Paths are
// resolved fully here, there are limitations though imagine:
//
// struct Foo<A> (A);
//
// impl Foo<isize> {
// fn test() -> ...
//
// impl Foo<f32> {
// fn test() -> ...
//
// fn main() {
// let a:i32 = Foo::test();
//
// there are multiple paths that test can resolve to Foo::<?>::test here
// so we cannot resolve this case
//
// canonical names:
//
// struct Foo<A> -> Foo
// impl Foo<isize>::fn test -> Foo::isize::test
// impl Foo<f32>::fn test -> Foo::f32::test
//
// Since there is the case we have the following paths for test:
//
// Foo::isize::test
// Foo::f32::test
// vs
// Foo::test
//
// but the lookup was simply Foo::test we must rely on type resolution to
// figure this type out in a similar fashion to method resolution with a
// probe phase
if (resolver->get_name_scope ().lookup (path, &resolved_node))
{
resolver->insert_resolved_name (expr->get_node_id (), resolved_node);
resolver->insert_new_definition (expr->get_node_id (),
Definition{expr->get_node_id (),
parent});
}
// check the type scope
else if (resolver->get_type_scope ().lookup (path, &resolved_node))
{
resolver->insert_resolved_type (expr->get_node_id (), resolved_node);
resolver->insert_new_definition (expr->get_node_id (),
Definition{expr->get_node_id (),
parent});
}
else
{
// attempt to fully resolve the path which is allowed to fail given
// the following scenario
//
// https://github.com/Rust-GCC/gccrs/issues/355 Paths are
// resolved fully here, there are limitations though imagine:
//
// struct Foo<A> (A);
//
// impl Foo<isize> {
// fn test() -> ...
//
// impl Foo<f32> {
// fn test() -> ...
//
// fn main() {
// let a:i32 = Foo::test();
//
// there are multiple paths that test can resolve to Foo::<?>::test
// here so we cannot resolve this case
//
// canonical names:
//
// struct Foo<A> -> Foo
// impl Foo<isize>::fn test -> Foo::isize::test
// impl Foo<f32>::fn test -> Foo::f32::test
//
// Since there is the case we have the following paths for test:
//
// Foo::isize::test
// Foo::f32::test
// vs
// Foo::test
//
// but the lookup was simply Foo::test we must rely on type resolution
// to figure this type out in a similar fashion to method resolution
// with a probe phase

// nothing more we can do we need the type resolver to try and resolve
// this
return;
}
}
}

Expand Down

0 comments on commit f1c9aee

Please sign in to comment.