diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-05-26 14:22:00 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-05-26 14:22:00 +0800 |
commit | 1b8e9e01a8ebce42e8ad3dca101180430b28c947 (patch) | |
tree | 32aba1e96d125ca8057cad2631ee0001fca30721 /src/hir_typeck | |
parent | 18476fb8893417176b7ba902eb9556225f96a4f7 (diff) | |
download | mrust-1b8e9e01a8ebce42e8ad3dca101180430b28c947.tar.gz |
HIR Typecheck - Handle struct syntax for unit structs
Diffstat (limited to 'src/hir_typeck')
-rw-r--r-- | src/hir_typeck/expr_check.cpp | 8 | ||||
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 23 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index 9e369e61..d0fe6a5d 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -473,6 +473,14 @@ namespace { TODO(sp, "Union in StructLiteral"); ), (Struct, + if( e->m_data.is_Unit() ) + { + ASSERT_BUG(node.span(), node.m_values.size() == 0, "Values provided for unit-like struct"); + ASSERT_BUG(node.span(), ! node.m_base_value, "Values provided for unit-like struct"); + return ; + } + + ASSERT_BUG(node.span(), e->m_data.is_Named(), "StructLiteral not pointing to a braced struct, instead " << e->m_data.tag_str() << " - " << ty); fields_ptr = &e->m_data.as_Named(); ) ) diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 605df162..5c69e20b 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1162,6 +1162,14 @@ namespace { TODO(node.span(), "StructLiteral of a union - " << ty); ), (Struct, + if( e->m_data.is_Unit() ) + { + ASSERT_BUG(node.span(), node.m_values.size() == 0, "Values provided for unit-like struct"); + ASSERT_BUG(node.span(), ! node.m_base_value, "Values provided for unit-like struct"); + return ; + } + + ASSERT_BUG(node.span(), e->m_data.is_Named(), "StructLiteral not pointing to a braced struct, instead " << e->m_data.tag_str() << " - " << ty); fields_ptr = &e->m_data.as_Named(); generics = &e->m_params; ) @@ -4200,7 +4208,7 @@ namespace { //} context.possible_equate_type_unsize_to(r_e.index, ty_dst); context.possible_equate_type_unsize_from(l_e.index, ty_src); - DEBUG("- Infer, add possibility"); + DEBUG("- Both infer, add possibility"); return false; } @@ -4232,8 +4240,16 @@ namespace { return true; } + // If the source can't unsize, equate + if( const auto* te = ty_src.m_data.opt_Slice() ) + { + (void)te; + context.equate_types(sp, ty_dst, ty_src); + return true; + } + context.possible_equate_type_unsize_from(l_e.index, ty_src); - DEBUG("- Infer, add possibility"); + DEBUG("- Dest infer, add possibility"); return false; ) @@ -4781,12 +4797,15 @@ namespace { } // TODO: Can this can unsize as well as convert to raw? + // - It _can_ unsize, TODO: context.equate_types(sp, *l_e.inner, *s_e.inner); // Add downcast auto span = node_ptr->span(); node_ptr = ::HIR::ExprNodeP(new ::HIR::ExprNode_Cast( mv$(span), mv$(node_ptr), ty_dst.clone() )); node_ptr->m_res_type = ty_dst.clone(); + // TODO: Add a coerce of src->&dst_inner + context.m_ivars.mark_change(); return true; ) |