diff options
| author | gingerBill <bill@gingerbill.org> | 2020-11-20 16:30:34 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-11-20 16:30:34 +0000 |
| commit | 260e28c0af2130a78862a5e253b98178fb480f02 (patch) | |
| tree | 99177b8376e3948d9b71472f7232fbc988029883 /src/check_expr.cpp | |
| parent | a14ea5b2b5068e679a961d0fd43e84eea593e2da (diff) | |
Fix casting of untyped strings
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index c67ad22b8..24676b3ce 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2161,6 +2161,17 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { return true; } + if (is_constant && is_type_untyped(src) && is_type_string(src)) { + if (is_type_u8_array(dst)) { + String s = operand->value.value_string; + return s.len == dst->Array.count; + } + if (is_type_rune_array(dst)) { + String s = operand->value.value_string; + return gb_utf8_strnlen(s.text, s.len) == dst->Array.count; + } + } + if (dst->kind == Type_Array && src->kind == Type_Array) { if (are_types_identical(dst->Array.elem, src->Array.elem)) { @@ -2962,7 +2973,7 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { break; } } else if (is_type_rune_array(t)) { - isize rune_count = s.len; + isize rune_count = gb_utf8_strnlen(s.text, s.len); if (rune_count == t->Array.count) { break; } |