summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-13 13:16:10 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-13 13:16:10 +0800
commit22e6d4807c7ffe646d43c700c5b045e606fbdc92 (patch)
tree43aa91abb5023f3c578a7e622f2a32027bb4fee8 /src
parent5e7385cc25a6facc1d3dea3510450b8c7fd29083 (diff)
downloadmrust-22e6d4807c7ffe646d43c700c5b045e606fbdc92.tar.gz
MIR Gen - Better error when types mismatch in assignment
Diffstat (limited to 'src')
-rw-r--r--src/mir/from_hir.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 78930715..79e20e50 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -314,17 +314,19 @@ namespace {
this->visit_node_ptr(node.m_slot);
auto dst = m_builder.get_result_lvalue(sp);
+ const auto& ty_slot = node.m_slot->m_res_type;
+ const auto& ty_val = node.m_value->m_res_type;
+ ASSERT_BUG(sp, ty_slot == ty_val, "Types must match for assignment - " << ty_slot << " != " << ty_val);
+
if( node.m_op != ::HIR::ExprNode_Assign::Op::None )
{
- ASSERT_BUG(sp, node.m_slot->m_res_type == node.m_value->m_res_type, "Types must match for op-assign");
-
- TU_IFLET(::HIR::TypeRef::Data, node.m_slot->m_res_type.m_data, Primitive, e,
+ TU_IFLET(::HIR::TypeRef::Data, ty_slot.m_data, Primitive, e,
switch(e)
{
case ::HIR::CoreType::Char:
case ::HIR::CoreType::Str:
case ::HIR::CoreType::Bool:
- BUG(sp, "Unsupported type for op-assign - " << node.m_slot->m_res_type);
+ BUG(sp, "Unsupported type for op-assign - " << ty_slot);
break;
default:
// Good.
@@ -332,10 +334,10 @@ namespace {
}
)
else {
- BUG(sp, "Unsupported type for op-assign - " << node.m_slot->m_res_type);
+ BUG(sp, "Unsupported type for op-assign - " << ty_slot);
}
- auto val_lv = m_builder.lvalue_or_temp( node.m_value->m_res_type, mv$(val) );
+ auto val_lv = m_builder.lvalue_or_temp( ty_val, mv$(val) );
::MIR::RValue res;
#define _(v) ::HIR::ExprNode_Assign::Op::v