From 87a189e90ecc0795d6a1b6e2f249aa9cf99c086e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 21 Jul 2019 22:31:08 +0800 Subject: Typecheck Expressions - Default to u8 when cast to char is seen --- src/hir_typeck/expr_cs.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index eb0ccbdb..6f9088a2 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2148,7 +2148,24 @@ namespace { ), (Primitive, // Don't have anything to contribute - this->m_completed = true; + // EXCEPT: `char` can only be casted from `u8` (but what about no-op casts?) + // - Hint the input (default) to be `u8` + if( e == ::HIR::CoreType::Char ) + { + if(this->m_is_fallback) + { + this->context.equate_types(sp, src_ty, ::HIR::CoreType::U8); + } + + if( !this->context.get_type(src_ty).m_data.is_Infer() ) + { + this->m_completed = true; + } + } + else + { + this->m_completed = true; + } ), (Path, this->context.equate_types_coerce(sp, tgt_ty, node.m_value); -- cgit v1.2.3