From 63e4a2341f1409eec1f2e58036cd01b24b66b8f0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 20 Nov 2020 16:24:23 +0000 Subject: Support string literals for fixed arrays of runes; Add %q support for arrays/slices of bytes --- src/check_expr.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index f258253f5..c67ad22b8 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2955,10 +2955,17 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { if (check_is_assignable_to(c, operand, elem)) { operand->mode = Addressing_Value; } else { - if (operand->value.kind == ExactValue_String && is_type_u8_array(t)) { + if (operand->value.kind == ExactValue_String) { String s = operand->value.value_string; - if (s.len == t->Array.count) { - break; + if (is_type_u8_array(t)) { + if (s.len == t->Array.count) { + break; + } + } else if (is_type_rune_array(t)) { + isize rune_count = s.len; + if (rune_count == t->Array.count) { + break; + } } } operand->mode = Addressing_Invalid; -- cgit v1.2.3