Merge pull request #2623 from laytan/fix-2615-cant-iterate-untyped-string

Fix #2615: can't iterate untyped string
This commit is contained in:
Jeroen van Rijn
2023-07-02 23:06:35 +02:00
committed by GitHub
4 changed files with 22 additions and 1 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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, '世')
}
}
}