diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-09 15:45:19 +1000 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-09 15:45:19 +1000 |
commit | a8df1eb68bfe5e267f2bbb49b354854ce4959ed0 (patch) | |
tree | e83060a37ee1049f715fbf9e41759a756bbbb4fe | |
parent | d2e985c2787150a7933b8842e6f192d5664aaa94 (diff) | |
download | mrust-a8df1eb68bfe5e267f2bbb49b354854ce4959ed0.tar.gz |
HIR Typecheck CS - range patterns
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index edf97de2..4c5e15bd 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -403,10 +403,13 @@ namespace { this->context.add_ivars( node.m_type ); this->context.add_binding(node.span(), node.m_pattern, node.m_type); - this->context.add_ivars( node.m_value->m_res_type ); - this->context.equate_types_coerce( node.span(), node.m_type, node.m_value ); - - node.m_value->visit( *this ); + if( node.m_value ) + { + this->context.add_ivars( node.m_value->m_res_type ); + this->context.equate_types_coerce( node.span(), node.m_type, node.m_value ); + + node.m_value->visit( *this ); + } } void visit(::HIR::ExprNode_Match& node) override { @@ -1938,28 +1941,36 @@ void Context::add_binding(const Span& sp, ::HIR::Pattern& pat, ::HIR::TypeRef& t //return ; } + + struct H { + static void handle_value(Context& context, const Span& sp, const ::HIR::TypeRef& type, const ::HIR::Pattern::Value& val) { + TU_MATCH(::HIR::Pattern::Value, (val), (v), + (Integer, + if( v.type != ::HIR::CoreType::Str ) { + context.equate_types(sp, type, ::HIR::TypeRef(v.type)); + } + ), + (String, + context.equate_types(sp, type, ::HIR::TypeRef::new_borrow( ::HIR::BorrowType::Shared, ::HIR::TypeRef(::HIR::CoreType::Str) )); + ), + (Named, + // TODO: Get type of the value and equate it + ) + ) + } + }; + // TU_MATCH(::HIR::Pattern::Data, (pat.m_data), (e), (Any, // Just leave it, the pattern says nothing ), (Value, - TU_MATCH(::HIR::Pattern::Value, (e.val), (v), - (Integer, - if( v.type != ::HIR::CoreType::Str ) { - this->equate_types(sp, type, ::HIR::TypeRef(v.type)); - } - ), - (String, - this->equate_types(sp, type, ::HIR::TypeRef::new_borrow( ::HIR::BorrowType::Shared, ::HIR::TypeRef(::HIR::CoreType::Str) )); - ), - (Named, - // TODO: Get type of the value and equate it - ) - ) + H::handle_value(*this, sp, type, e.val); ), (Range, - TODO(sp, "Range pattern"); + H::handle_value(*this, sp, type, e.start); + H::handle_value(*this, sp, type, e.end); ), (Box, TODO(sp, "Box pattern"); |