diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-10 18:06:11 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-10 18:06:11 +0800 |
commit | 2288ef49a128471d866e2c83a5fcf84c3803964c (patch) | |
tree | d6b2c92dd12d48fdf9271eb32e0789e12cd6365a /src | |
parent | 424c3160e95de4452631376876dcaeefce3dae11 (diff) | |
download | mrust-2288ef49a128471d866e2c83a5fcf84c3803964c.tar.gz |
HIR Typecheck Expr - Allow casts to become coerces
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 437050ad..5220bdcd 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1807,11 +1807,6 @@ namespace { return ; } - // TODO: Check if this is actually a coercion. - if( tgt_ty.m_data.is_Path() || tgt_ty.m_data.is_Generic() ) { - ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " from " << this->context.m_ivars.fmt_type(src_ty)); - } - TU_MATCH( ::HIR::TypeRef::Data, (tgt_ty.m_data), (e), (Infer, // Can't know anything @@ -1826,10 +1821,29 @@ namespace { this->m_completed = true; ), (Path, - BUG(sp, "_Cast Path"); + TU_MATCHA( (e.binding), (be), + (Unbound, + BUG(sp, "Encountered unbound type in _Cast Path - " << tgt_ty); + ), + (Opaque, + // TODO: Bounds search + TODO(sp, "Cast Path::Opaque with CoerceUnsized - " << tgt_ty); + ), + (Struct, + if( !be->m_markings.can_coerce ) + ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); + ), + (Enum, + if( !be->m_markings.can_coerce ) + ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); + ) + ) + this->context.equate_types_coerce(sp, tgt_ty, node.m_value); + this->m_completed = true; + return ; ), (Generic, - BUG(sp, "_Cast Generic"); + TODO(sp, "_Cast Generic"); ), (TraitObject, ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); |