From fc81008ab5e8568eb7a76f6311919a44b9e4d8a4 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sun, 2 Jul 2023 22:18:25 +0200 Subject: [PATCH 1/2] Fix #2615: can't iterate untyped string --- src/check_stmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 964ff1842..a15977b7d 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1528,7 +1528,7 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) Type *t = base_type(type_deref(operand.type)); switch (t->kind) { case Type_Basic: - if (t->Basic.kind == Basic_string) { + if (t->Basic.kind == Basic_string || t->Basic.kind == Basic_UntypedString) { is_possibly_addressable = false; array_add(&vals, t_rune); array_add(&vals, t_int); From a3e2d90f4cc591b7c2a3957aba4dc4a56451d372 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sun, 2 Jul 2023 22:55:28 +0200 Subject: [PATCH 2/2] add test --- tests/issues/run.bat | 1 + tests/issues/run.sh | 1 + tests/issues/test_issue_2615.odin | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/issues/test_issue_2615.odin diff --git a/tests/issues/run.bat b/tests/issues/run.bat index bf49bc85b..105d474e3 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -13,6 +13,7 @@ set COMMON=-collection:tests=..\.. ..\..\..\odin test ..\test_issue_2087.odin %COMMON% -file || exit /b ..\..\..\odin build ..\test_issue_2113.odin %COMMON% -file -debug || exit /b ..\..\..\odin test ..\test_issue_2466.odin %COMMON% -file || exit /b +..\..\..\odin test ..\test_issue_2615.odin %COMMON% -file || exit /b @echo off diff --git a/tests/issues/run.sh b/tests/issues/run.sh index b0c43572f..c4c53e7e1 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -16,6 +16,7 @@ $ODIN test ../test_issue_2056.odin $COMMON -file $ODIN test ../test_issue_2087.odin $COMMON -file $ODIN build ../test_issue_2113.odin $COMMON -file -debug $ODIN test ../test_issue_2466.odin $COMMON -file +$ODIN test ../test_issue_2615.odin $COMMON -file if [[ $($ODIN build ../test_issue_2395.odin $COMMON -file 2>&1 >/dev/null | grep -c "$NO_NIL_ERR") -eq 2 ]] ; then echo "SUCCESSFUL 1/1" else diff --git a/tests/issues/test_issue_2615.odin b/tests/issues/test_issue_2615.odin new file mode 100644 index 000000000..229e5c35b --- /dev/null +++ b/tests/issues/test_issue_2615.odin @@ -0,0 +1,19 @@ +// Tests issue https://github.com/odin-lang/Odin/issues/2615 +// Cannot iterate over string literals +package test_issues + +import "core:testing" + +@(test) +test_cannot_iterate_over_string_literal :: proc(t: ^testing.T) { + for c, i in "fo世" { + switch i { + case 0: + testing.expect_value(t, c, 'f') + case 1: + testing.expect_value(t, c, 'o') + case 2: + testing.expect_value(t, c, '世') + } + } +}