From 0459a4ee12ad98be68f92645c9a1483d117c0a15 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 5 Aug 2016 12:51:26 +0800 Subject: HIR Typecheck CS - Add cast when going from &T to *const T --- src/hir_typeck/expr_cs.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 77f48d6a..887c309b 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -3226,7 +3226,18 @@ namespace { (Pointer, // Pointers coerce from borrows and similar pointers TU_IFLET(::HIR::TypeRef::Data, ty_src.m_data, Borrow, r_e, + if( r_e.type != l_e.type ) { + ERROR(sp, E0000, "Type mismatch between " << ty_dst << " and " << ty_src << " - Mutability differs"); + } context.equate_types(sp, *l_e.inner, *r_e.inner); + + // Add downcast + auto span = node_ptr->span(); + node_ptr->m_res_type = ty_src.clone(); + node_ptr = ::HIR::ExprNodeP(new ::HIR::ExprNode_Cast( mv$(span), mv$(node_ptr), ty_dst.clone() )); + node_ptr->m_res_type = ty_dst.clone(); + + context.m_ivars.mark_change(); return true; ) else TU_IFLET(::HIR::TypeRef::Data, ty_src.m_data, Pointer, r_e, -- cgit v1.2.3