aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp13
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;
}