diff --git a/docs/image/Overview.png b/docs/image/overview.png similarity index 100% rename from docs/image/Overview.png rename to docs/image/overview.png diff --git a/kclvm/evaluator/src/snapshots/kclvm_evaluator__tests__list_comp1.snap b/kclvm/evaluator/src/snapshots/kclvm_evaluator__tests__list_comp1.snap new file mode 100644 index 000000000..07d14f179 --- /dev/null +++ b/kclvm/evaluator/src/snapshots/kclvm_evaluator__tests__list_comp1.snap @@ -0,0 +1,7 @@ +--- +source: evaluator/src/tests.rs +expression: "format! (\"{}\", evaluator.run().unwrap().1)" +--- +a: +- 你 +- 好 diff --git a/kclvm/evaluator/src/tests.rs b/kclvm/evaluator/src/tests.rs index c61a951d1..992728a9f 100644 --- a/kclvm/evaluator/src/tests.rs +++ b/kclvm/evaluator/src/tests.rs @@ -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 { diff --git a/kclvm/runtime/src/value/iter.rs b/kclvm/runtime/src/value/iter.rs index 8e56b7828..29acdd537 100644 --- a/kclvm/runtime/src/value/iter.rs +++ b/kclvm/runtime/src/value/iter.rs @@ -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());