diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-07-21 22:31:08 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-07-21 22:31:08 +0800 |
commit | 87a189e90ecc0795d6a1b6e2f249aa9cf99c086e (patch) | |
tree | 2ade51e26bcdff6915a655d48490cb85f2cdee01 /src | |
parent | fa115063f9bbbded2463b0057d5dd4b8d1ab0483 (diff) | |
download | mrust-87a189e90ecc0795d6a1b6e2f249aa9cf99c086e.tar.gz |
Typecheck Expressions - Default to u8 when cast to char is seen
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
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); |