summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-08 23:50:32 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-08 23:50:32 +0800
commit7685ecc25ad47d369ea250d36c71bae4cec2d9a1 (patch)
treee4a8e245ea15179a3d06f1e1ca89487a444eff9b
parentb61f4dc10daca6590b526801d971d4a8368062e9 (diff)
downloadmrust-7685ecc25ad47d369ea250d36c71bae4cec2d9a1.tar.gz
HIR Typecheck - Handle `Self` when looking up associated types
-rw-r--r--src/hir_typeck/expr.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index 043456e0..9e7b4b5a 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -1253,8 +1253,15 @@ namespace {
if( ty.m_data.is_Infer() )
return this->get_type(ty);
else TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Generic, e,
- assert( impl_args.at(e.binding) );
- return *impl_args.at(e.binding);
+ if( e.binding == 0xFFFF ) {
+ //TODO(sp, "Look up 'Self' in expand_associated_types::expand_placeholder (" << *e2.type << ")");
+ return *e2.type;
+ }
+ else {
+ assert(e.binding < impl_args.size());
+ assert( impl_args[e.binding] );
+ return *impl_args[e.binding];
+ }
)
else
return ty;
@@ -2839,6 +2846,7 @@ void Typecheck_Code(TypecheckContext context, const ::HIR::TypeRef& result_type,
{
TRACE_FUNCTION;
+ // Convert ExprPtr into unique_ptr for the execution of this function
auto root_ptr = expr.into_unique();
//context.apply_equality(expr->span(), result_type, expr->m_res_type);
@@ -2850,10 +2858,7 @@ void Typecheck_Code(TypecheckContext context, const ::HIR::TypeRef& result_type,
}
// - Apply equality between the node result and the expected type
DEBUG("- Apply RV");
- {
- // Convert ExprPtr into unique_ptr for the execution of this function
- context.apply_equality(root_ptr->span(), result_type, root_ptr->m_res_type, &root_ptr);
- }
+ context.apply_equality(root_ptr->span(), result_type, root_ptr->m_res_type, &root_ptr);
context.dump();
// 2. Iterate through nodes applying rules until nothing changes
@@ -2872,6 +2877,7 @@ void Typecheck_Code(TypecheckContext context, const ::HIR::TypeRef& result_type,
expr = ::HIR::ExprPtr( mv$(root_ptr) );
context.dump();
{
+ DEBUG("==== VALIDATE ====");
ExprVisitor_Apply visitor { context };
expr->visit( visitor );
}