diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-06 13:55:26 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-06 13:55:26 +0800 |
commit | 4559d673ddb00f14093318926c76152b580ae6f9 (patch) | |
tree | 67fbc6a16e87b395976061a4a55a91e345e38c03 | |
parent | 1fe42a193fbd595691ba213cd21d5b68059fcfad (diff) | |
download | mrust-4559d673ddb00f14093318926c76152b580ae6f9.tar.gz |
HIR Typecheck Validate - Handle tuple indexing
-rw-r--r-- | src/hir_typeck/expr_check.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index f8cd8202..246b3c4f 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -421,14 +421,22 @@ namespace { void visit(::HIR::ExprNode_Field& node) override { const auto& sp = node.span(); - const auto& str_ty = node.m_value->m_res_type; - ASSERT_BUG(sp, str_ty.m_data.is_Path(), "Value type of _Field isn't Path"); - const auto& ty_e = str_ty.m_data.as_Path(); - ASSERT_BUG(sp, ty_e.binding.is_Struct(), "Value type of _Field isn't a Struct"); - //const auto& str = *ty_e.binding.as_Struct(); - // TODO: Triple-check result, but that probably isn't needed + bool is_index = ( '0' <= node.m_field[0] && node.m_field[0] <= '9' ); + if( str_ty.m_data.is_Tuple() ) + { + ASSERT_BUG(sp, is_index, "Non-index _Field on tuple"); + } + else + { + ASSERT_BUG(sp, str_ty.m_data.is_Path(), "Value type of _Field isn't Path - " << str_ty); + const auto& ty_e = str_ty.m_data.as_Path(); + ASSERT_BUG(sp, ty_e.binding.is_Struct(), "Value type of _Field isn't a Struct - " << str_ty); + //const auto& str = *ty_e.binding.as_Struct(); + + // TODO: Triple-check result, but that probably isn't needed + } node.m_value->visit( *this ); } |