Add missing canonicalization of slices and raw pointer types

When we intercept impl blocks for slices or raw pointers we must generate
the canonical path for this for name resolution this adds in the missing
visitors which will generate the path. Previously this was defaulting to
empty path segments and then hitting an assertion when we append the
empty segment.

Fixes #1005
This commit is contained in:
Philip Herron 2022-03-10 13:26:06 +00:00
parent 77a4950744
commit 31413ebacf
3 changed files with 47 additions and 0 deletions

View File

@ -167,6 +167,45 @@ ResolveTypeToCanonicalPath::visit (AST::ReferenceType &ref)
result = result.append (ident_seg);
}
void
ResolveTypeToCanonicalPath::visit (AST::RawPointerType &ref)
{
auto inner_type
= ResolveTypeToCanonicalPath::resolve (*ref.get_type_pointed_to ().get (),
include_generic_args_flag,
type_resolve_generic_args_flag);
std::string segment_string ("*");
switch (ref.get_pointer_type ())
{
case AST::RawPointerType::PointerType::MUT:
segment_string += "mut ";
break;
case AST::RawPointerType::PointerType::CONST:
segment_string += "const ";
break;
}
segment_string += inner_type.get ();
auto ident_seg = CanonicalPath::new_seg (ref.get_node_id (), segment_string);
result = result.append (ident_seg);
}
void
ResolveTypeToCanonicalPath::visit (AST::SliceType &slice)
{
auto inner_type
= ResolveTypeToCanonicalPath::resolve (*slice.get_elem_type ().get (),
include_generic_args_flag,
type_resolve_generic_args_flag);
std::string segment_string = "[" + inner_type.get () + "]";
auto ident_seg
= CanonicalPath::new_seg (slice.get_node_id (), segment_string);
result = result.append (ident_seg);
}
void
ResolveType::visit (AST::ReferenceType &type)
{

View File

@ -122,6 +122,10 @@ public:
}
}
void visit (AST::SliceType &slice) override;
void visit (AST::RawPointerType &ptr) override;
void visit (AST::ReferenceType &ref) override;
void visit (AST::TypePathSegmentGeneric &seg) override;

View File

@ -0,0 +1,4 @@
// { dg-additional-options "-w" }
impl<T> *const T {
fn test(self) {}
}