Skip to content

Commit

Permalink
Iterate over string
Browse files Browse the repository at this point in the history
  • Loading branch information
faze-geek committed Jun 24, 2023
1 parent 4662acb commit a374001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration_tests/test_list_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ def test_issue_1882():
for i in [1, 2, 3]:
assert i + 1 == x[i - 1]

def test_iterate_over_string():
s: str
i: i32 = 0
temp: str = "abcd"
for s in "abcd":
assert s == temp[i]
i+=1

def main0():
x: list[i32] = return_empty_list_of_tuples()
print(len(x))

assert len(x) == 0
test_issue_1882()
test_iterate_over_string()

main0()
2 changes: 1 addition & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
throw SemanticError("Only Name is supported for Subscript",
sbt->base.base.loc);
}
} else if (AST::is_a<AST::List_t>(*x.m_iter)) {
} else if (AST::is_a<AST::List_t>(*x.m_iter) || AST::is_a<AST::ConstantStr_t>(*x.m_iter) ) {
visit_expr(*x.m_iter);
ASR::expr_t *target = ASRUtils::EXPR(tmp);
ASR::ttype_t *loop_src_var_ttype = ASRUtils::expr_type(target);
Expand Down

0 comments on commit a374001

Please sign in to comment.