diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-05 18:57:55 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-05 18:57:55 +0800 |
commit | 96452c8d486d1284b0846a13ae5624711f3b5485 (patch) | |
tree | dbb2aa52f0a828bd1c3dd6a3e0e44cf34804982c /src | |
parent | 0e56114ba63fcf4592e1828345c7c4c6cb9c115e (diff) | |
download | mrust-96452c8d486d1284b0846a13ae5624711f3b5485.tar.gz |
HIR Typecheck CS - Pointer casts
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index ff368200..b848c5cc 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2100,16 +2100,61 @@ namespace { ) else TU_IFLET(::HIR::TypeRef::Data, ty_r.m_data, Infer, r_e, // Leave for now + if( r_e.ty_class != ::HIR::InferClass::None ) { + // ERROR: Must be compatible + context.equate_types(sp, ty, ty_r); + BUG(sp, "Type error expected " << ty << " == " << ty_r); + } + return false; ) else { // Error - Must be compatible // - Hand off to equate context.equate_types(sp, ty, ty_r); + BUG(sp, "Type error expected " << ty << " == " << ty_r); } ), (Pointer, // TODO: Pointers coerce from borrows and similar pointers - TODO(sp, "check_coerce - Coercion to " << ty); + TU_IFLET(::HIR::TypeRef::Data, ty_r.m_data, Borrow, r_e, + context.equate_types(sp, *l_e.inner, *r_e.inner); + return true; + ) + else TU_IFLET(::HIR::TypeRef::Data, ty_r.m_data, Pointer, r_e, + // If using `*mut T` where `*const T` is expected - add cast + if( l_e.type == ::HIR::BorrowType::Shared && r_e.type == ::HIR::BorrowType::Unique ) { + context.equate_types(sp, *l_e.inner, *r_e.inner); + + // Add cast down + auto span = node_ptr->span(); + node_ptr->m_res_type = ty_r.clone(); + node_ptr = ::HIR::ExprNodeP(new ::HIR::ExprNode_Cast( mv$(span), mv$(node_ptr), ty.clone() )); + node_ptr->m_res_type = ty.clone(); + + context.m_ivars.mark_change(); + return true; + } + + if( l_e.type != r_e.type ) { + ERROR(sp, E0000, "Type mismatch between " << ty << " and " << ty_r << " - Pointer mutability differs"); + } + context.equate_types(sp, *l_e.inner, *r_e.inner); + return true; + ) + else TU_IFLET(::HIR::TypeRef::Data, ty_r.m_data, Infer, r_e, + if( r_e.ty_class != ::HIR::InferClass::None ) { + // ERROR: Must be compatible + context.equate_types(sp, ty, ty_r); + BUG(sp, "Type error expected " << ty << " == " << ty_r); + } + // Can't do much for now + return false; + ) + else { + // Error: Must be compatible + context.equate_types(sp, ty, ty_r); + BUG(sp, "Type error expected " << ty << " == " << ty_r); + } ), (Function, // TODO: Could capture-less closures coerce to fn() types? |