Skip to content

Commit

Permalink
Typecheck - Allow fn to any sized pointer cast
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 29, 2024
1 parent bcf9bd2 commit 4b818fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/hir_typeck/expr_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@ namespace {
//}
}
TU_ARMA(Function, se) {
if( de.inner != ::HIR::TypeRef::new_unit() && de.inner != ::HIR::CoreType::U8 && de.inner != ::HIR::CoreType::I8 ) {
if( de.inner == ::HIR::TypeRef::new_unit() || de.inner == ::HIR::CoreType::U8 || de.inner == ::HIR::CoreType::I8 ) {
}
else if( m_resolve.type_is_sized(sp, de.inner) ) {
// Allow it.
}
else {
ERROR(sp, E0000, "Invalid cast to " << dst_ty << " from " << src_ty);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/hir_typeck/expr_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ namespace {
// Keep around.
}
else {
ERROR(sp, E0000, "Invalid cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " from " << src_ty);
//ERROR(sp, E0000, "Invalid cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " from " << src_ty);
// TODO: Only allow thin pointers? `c_void` is used in 1.74 libstd
this->m_completed = true;
}
}
TU_ARMA(Primitive, s_e) {
Expand Down
2 changes: 1 addition & 1 deletion src/mir/from_hir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ namespace {
}
else if( /*const auto* se =*/ ty_in.data().opt_Function() )
{
if( de.inner != ::HIR::TypeRef::new_unit() && de.inner != ::HIR::CoreType::U8 && de.inner != ::HIR::CoreType::I8 ) {
if( !m_builder.resolve().type_is_sized(node.span(), de.inner) ) {
BUG(node.span(), "Cannot cast to " << ty_out << " from " << ty_in);
}
// Valid
Expand Down

0 comments on commit 4b818fb

Please sign in to comment.