bugfix list index

This commit is contained in:
Shautvast 2025-11-09 22:15:54 +01:00
parent ec8fe5a795
commit 9ee8f193aa
3 changed files with 4 additions and 3 deletions

View file

@ -163,7 +163,8 @@ let c = b + "world"
``` ```
**dates and time** **dates and time**
Create a date literal with
Create a date with a literal:
``` ```
let d:date = d"1979-12-16 16:12:19.000 +01:00" let d:date = d"1979-12-16 16:12:19.000 +01:00"
``` ```

View file

@ -37,7 +37,7 @@ mod tests {
#[test] #[test]
fn index_in_list_literal() { fn index_in_list_literal() {
assert_eq!(run(r#"["abc","def"][0]"#), Ok(Value::String("abc".into()))) assert_eq!(run(r#"["abc","def"][1]"#), Ok(Value::String("def".into())))
} }
#[test] #[test]

View file

@ -193,7 +193,7 @@ impl Vm {
OP_LIST_GET => { OP_LIST_GET => {
let index_high = self.read(chunk); let index_high = self.read(chunk);
let index_low = self.read(chunk); let index_low = self.read(chunk);
let index = index_high <<16 + index_low; let index = (index_high <<16) + index_low;
let list = self.pop(); let list = self.pop();
if let Value::List(list) = list { if let Value::List(list) = list {
self.push(list.get(index).cloned().unwrap()) self.push(list.get(index).cloned().unwrap())