Skip to content

Commit

Permalink
fix: fix iter unicode string (#1802)
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Dec 30, 2024
1 parent 27a32d0 commit d9869c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: evaluator/src/tests.rs
expression: "format! (\"{}\", evaluator.run().unwrap().1)"
---
a:
-
-
4 changes: 4 additions & 0 deletions kclvm/evaluator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ data2 = Data {
version = "v0.1.0"
"#}

evaluator_snapshot! {list_comp1, r#"
a = [ x for x in "你好"]
"#}

#[test]
fn test_if_stmt_setters() {
let p = load_packages(&LoadPackageOptions {
Expand Down
3 changes: 3 additions & 0 deletions kclvm/runtime/src/value/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ impl ValueIterator {
}
match *host.rc.borrow() {
Value::str_value(ref s) => {
if self.pos >= s.chars().count() as i32 {
return None;
}
let ch = s.chars().nth(self.pos as usize).unwrap();
self.cur_key = ValueRef::int(self.pos as i64);
self.cur_val = ValueRef::str(&ch.to_string());
Expand Down

0 comments on commit d9869c3

Please sign in to comment.