summaryrefslogtreecommitdiff
path: root/src/hir_typeck/expr_check.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-11-18 13:45:57 +0800
committerJohn Hodge <tpg@mutabah.net>2016-11-18 13:45:57 +0800
commitf4e40a36f65e2ab6ed0b62566ca0bf77ccc0aef9 (patch)
treebda8d25f83c612e5556cc78df388d2a7874bf306 /src/hir_typeck/expr_check.cpp
parent6d16e113d9b01e10f017ce2ecd3bcd2552b6b3e5 (diff)
downloadmrust-f4e40a36f65e2ab6ed0b62566ca0bf77ccc0aef9.tar.gz
HIR Typecheck Validate - Expand ErasedType in callee returns
Diffstat (limited to 'src/hir_typeck/expr_check.cpp')
-rw-r--r--src/hir_typeck/expr_check.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp
index b2cda61b..9102652a 100644
--- a/src/hir_typeck/expr_check.cpp
+++ b/src/hir_typeck/expr_check.cpp
@@ -48,7 +48,7 @@ namespace {
if( tpl.m_data.is_ErasedType() )
{
const auto& e = tpl.m_data.as_ErasedType();
- ASSERT_BUG(sp, e.m_index < node_ptr.m_erased_types.size(), "Erased type index OOB - " << e.m_index << " >= " << node_ptr.m_erased_types.size() << " - " << tpl);
+ ASSERT_BUG(sp, e.m_index < node_ptr.m_erased_types.size(), "Erased type index OOB - " << e.m_origin << " " << e.m_index << " >= " << node_ptr.m_erased_types.size());
// TODO: Emit checks on bounds
rv = node_ptr.m_erased_types[e.m_index].clone();
return true;
@@ -692,7 +692,27 @@ namespace {
DEBUG("= " << cache.m_arg_types.back());
}
DEBUG("Ret " << fcn.m_return);
- cache.m_arg_types.push_back( monomorphise_type_with(sp, fcn.m_return, monomorph_cb, false) );
+ // Replace ErasedType and monomorphise
+ cache.m_arg_types.push_back( clone_ty_with(sp, fcn.m_return, [&](const auto& tpl, auto& rv) {
+ if( tpl.m_data.is_Infer() ) {
+ BUG(sp, "");
+ }
+ else if( tpl.m_data.is_Generic() ) {
+ rv = monomorph_cb(tpl).clone();
+ return true;
+ }
+ else if( tpl.m_data.is_ErasedType() ) {
+ const auto& e = tpl.m_data.as_ErasedType();
+
+ ASSERT_BUG(sp, e.m_index < fcn_ptr->m_code.m_erased_types.size(), "");
+ const auto& erased_type_replacement = fcn_ptr->m_code.m_erased_types.at(e.m_index);
+ rv = monomorphise_type_with(sp, erased_type_replacement, monomorph_cb, false);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }) );
m_resolve.expand_associated_types(sp, cache.m_arg_types.back());
DEBUG("= " << cache.m_arg_types.back());