From bbe5262a00b41053355286e9a42551c06614da2b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 29 Oct 2017 14:27:13 +0800 Subject: HIR Typecheck - Allow casting function pointers to *const i8 --- src/hir_typeck/expr_check.cpp | 2 +- src/hir_typeck/expr_cs.cpp | 8 ++++++-- src/mir/from_hir.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index 14cc488c..d9cbc957 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -311,7 +311,7 @@ namespace { //} ), (Function, - if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 ) { + if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 && *de.inner != ::HIR::CoreType::I8 ) { ERROR(sp, E0000, "Invalid cast to " << dst_ty << " from " << src_ty); } ), diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index ea040bf0..b665b14e 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2081,17 +2081,21 @@ namespace { return ; ), (Pointer, + const auto& ity = this->context.get_type(*e.inner); TU_MATCH_DEF( ::HIR::TypeRef::Data, (src_ty.m_data), (s_e), ( ERROR(sp, E0000, "Invalid cast to pointer from " << src_ty); ), (Function, // TODO: What is the valid set? *const () and *const u8 at least are allowed - if( *e.inner == ::HIR::TypeRef::new_unit() || *e.inner == ::HIR::CoreType::U8 ) { + if( ity == ::HIR::TypeRef::new_unit() || ity == ::HIR::CoreType::U8 || ity == ::HIR::CoreType::I8 ) { this->m_completed = true; } + else if( ity.m_data.is_Infer() ) { + // Keep around. + } else { - ERROR(sp, E0000, "Invalid cast to " << tgt_ty << " from " << src_ty); + ERROR(sp, E0000, "Invalid cast to " << this->context.m_ivars.fmt_type(tgt_ty) << " from " << src_ty); } ), (Primitive, diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 8ea22cef..2a02b166 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1247,7 +1247,7 @@ namespace { // Valid ) else TU_IFLET( ::HIR::TypeRef::Data, ty_in.m_data, Function, se, - if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 ) { + if( *de.inner != ::HIR::TypeRef::new_unit() && *de.inner != ::HIR::CoreType::U8 && *de.inner != ::HIR::CoreType::I8 ) { BUG(node.span(), "Cannot cast to " << ty_out << " from " << ty_in); } // Valid -- cgit v1.2.3