summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-09-30 22:55:58 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-09-30 22:55:58 +0800
commit0a591f10475f29ce18a472eef363822c80443994 (patch)
treed1abf5b8d3ab5cee4a54649cb297dbb3a5c1db6b
parenteb8c70a071a91ac8f2dd2710206e7d46c4e3bd4d (diff)
downloadmrust-0a591f10475f29ce18a472eef363822c80443994.tar.gz
HIR Typecheck - Coercion point at indexing
-rw-r--r--src/hir/expr.hpp4
-rw-r--r--src/hir_typeck/expr_cs.cpp5
2 files changed, 8 insertions, 1 deletions
diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp
index d099ecb4..e1a8d77a 100644
--- a/src/hir/expr.hpp
+++ b/src/hir/expr.hpp
@@ -409,6 +409,10 @@ struct ExprNode_Index:
::HIR::ExprNodeP m_value;
::HIR::ExprNodeP m_index;
+ struct {
+ ::HIR::TypeRef index_ty;
+ } m_cache;
+
ExprNode_Index(Span sp, ::HIR::ExprNodeP val, ::HIR::ExprNodeP index):
ExprNode(mv$(sp)),
m_value( mv$(val) ),
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 3d2ba634..e394e9b2 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -1074,10 +1074,12 @@ namespace {
TRACE_FUNCTION_F(&node << " ... [ ... ]");
this->context.add_ivars( node.m_value->m_res_type );
+ node.m_cache.index_ty = this->context.m_ivars.new_ivar_tr();
this->context.add_ivars( node.m_index->m_res_type );
node.m_value->visit( *this );
node.m_index->visit( *this );
+ this->context.equate_types_coerce(node.m_index->span(), node.m_cache.index_ty, node.m_index);
this->context.add_revisit(node);
}
@@ -2345,7 +2347,8 @@ namespace {
void visit(::HIR::ExprNode_Index& node) override {
const auto& lang_Index = this->context.m_crate.get_lang_item_path(node.span(), "index");
const auto& val_ty = this->context.get_type(node.m_value->m_res_type);
- const auto& idx_ty = this->context.get_type(node.m_index->m_res_type);
+ //const auto& idx_ty = this->context.get_type(node.m_index->m_res_type);
+ const auto& idx_ty = this->context.get_type(node.m_cache.index_ty);
TRACE_FUNCTION_F("Index: val=" << val_ty << ", idx=" << idx_ty << "");
this->context.equate_types_from_shadow(node.span(), node.m_res_type);