summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir_typeck/expr_check.cpp16
-rw-r--r--src/hir_typeck/expr_cs.cpp12
-rw-r--r--src/mir/from_hir.cpp14
3 files changed, 38 insertions, 4 deletions
diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp
index b517e421..0b700c5d 100644
--- a/src/hir_typeck/expr_check.cpp
+++ b/src/hir_typeck/expr_check.cpp
@@ -255,11 +255,25 @@ namespace {
),
(Pointer,
// TODO: Sized check - can't cast to a fat pointer from a thin one
+ //if( ! this->m_resolve.type_is_sized(*de.inner) ) {
+ // ERROR(sp, E0000, "Invalid cast to fat pointer " << dst_ty << " from " << src_ty);
+ //}
),
(Primitive,
- if( se != ::HIR::CoreType::Usize ) {
+ switch(se)
+ {
+ case ::HIR::CoreType::Bool:
+ case ::HIR::CoreType::Char:
+ case ::HIR::CoreType::Str:
+ case ::HIR::CoreType::F32:
+ case ::HIR::CoreType::F64:
ERROR(sp, E0000, "Invalid cast to " << dst_ty << " from " << src_ty);
+ default:
+ break;
}
+ //if( ! this->m_resolve.type_is_sized(*de.inner) ) {
+ // ERROR(sp, E0000, "Invalid cast to fat pointer " << dst_ty << " from " << src_ty);
+ //}
),
(Function,
if( *de.inner != ::HIR::TypeRef::new_unit() ) {
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index ebb17f52..6af70d30 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -1754,10 +1754,18 @@ namespace {
}
),
(Primitive,
- if( s_e != ::HIR::CoreType::Usize ) {
+ switch(s_e)
+ {
+ case ::HIR::CoreType::Bool:
+ case ::HIR::CoreType::Char:
+ case ::HIR::CoreType::Str:
+ case ::HIR::CoreType::F32:
+ case ::HIR::CoreType::F64:
ERROR(sp, E0000, "Invalid cast to pointer from " << src_ty);
+ default:
+ break;
}
- // TODO: Can't be to a fat pointer though.
+ // NOTE: Can't be to a fat pointer though - This is checked by the later pass (once all types are known and thus sized-ness is known)
this->m_completed = true;
),
(Infer,
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 586a152e..7ead584c 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -777,7 +777,19 @@ namespace {
BUG(node.span(), "Invalid cast to " << ty_out);
),
(Pointer,
- if( ty_in.m_data.is_Primitive() && ty_in.m_data.as_Primitive() == ::HIR::CoreType::Usize ) {
+ if( ty_in.m_data.is_Primitive() ) {
+ const auto& ie = ty_in.m_data.as_Primitive();
+ switch(ie)
+ {
+ case ::HIR::CoreType::Bool:
+ case ::HIR::CoreType::Char:
+ case ::HIR::CoreType::Str:
+ case ::HIR::CoreType::F32:
+ case ::HIR::CoreType::F64:
+ BUG(node.span(), "Cannot cast to pointer from " << ty_in);
+ default:
+ break;
+ }
// TODO: Only valid if T: Sized in *{const/mut/move} T
}
else TU_IFLET( ::HIR::TypeRef::Data, ty_in.m_data, Borrow, se,