diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-05 17:47:33 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-05 17:47:33 +0100 |
| commit | 9a99beec94a5b02aa91a363b299d4795ef52c0fa (patch) | |
| tree | 0119a005ad8256b641a59d20645c5dbd16a7955c | |
| parent | 93138e2d4bb7dbc09ab6ef3c6e139881a8f3bc61 (diff) | |
Fix `array.pop()`
| -rw-r--r-- | src/model/array.rs | 5 | ||||
| -rw-r--r-- | src/model/methods.rs | 2 | ||||
| -rw-r--r-- | tests/typ/compiler/array.typ | 2 |
3 files changed, 4 insertions, 5 deletions
diff --git a/src/model/array.rs b/src/model/array.rs index be35c651..12abac4e 100644 --- a/src/model/array.rs +++ b/src/model/array.rs @@ -84,9 +84,8 @@ impl Array { } /// Remove the last value in the array. - pub fn pop(&mut self) -> StrResult<()> { - Arc::make_mut(&mut self.0).pop().ok_or_else(array_is_empty)?; - Ok(()) + pub fn pop(&mut self) -> StrResult<Value> { + Arc::make_mut(&mut self.0).pop().ok_or_else(array_is_empty) } /// Insert a value at the specified index. diff --git a/src/model/methods.rs b/src/model/methods.rs index 5da64fa2..c0b63669 100644 --- a/src/model/methods.rs +++ b/src/model/methods.rs @@ -144,7 +144,7 @@ pub fn call_mut( match value { Value::Array(array) => match method { "push" => array.push(args.expect("value")?), - "pop" => array.pop().at(span)?, + "pop" => output = array.pop().at(span)?, "insert" => { array.insert(args.expect("index")?, args.expect("value")?).at(span)? } diff --git a/tests/typ/compiler/array.typ b/tests/typ/compiler/array.typ index 2fea8632..550d928a 100644 --- a/tests/typ/compiler/array.typ +++ b/tests/typ/compiler/array.typ @@ -100,7 +100,7 @@ // Test the `push` and `pop` methods. #{ let tasks = (a: (1, 2, 3), b: (4, 5, 6)) - tasks.at("a").pop() + test(tasks.at("a").pop(), 3) tasks.b.push(7) test(tasks.a, (1, 2)) test(tasks.at("b"), (4, 5, 6, 7)) |
