Commit c3631ce9 authored by Hero Bird's avatar Hero Bird Committed by GitHub

[core] implement fix for #193 (#194)

parent 0f249fa4
......@@ -340,6 +340,10 @@ where
"[ink_core::Vec::swap_remove] Error: \
expected `Some` value since vector is not empty",
);
if self.is_empty() {
// This is true if the vec had only 1 element.
return Some(popped)
}
Some(self.cells.put(n, popped).expect(
"[ink_core::Vec::swap_remove] Error: \
expected success since the vector is not empty",
......
......@@ -286,3 +286,14 @@ fn iter_size_hint() {
assert_eq!(iter.size_hint(), (3, Some(3)));
})
}
#[test]
fn regression_issue_193() {
run_test(|| {
let mut vec = new_empty_vec();
vec.push(5);
assert_eq!(vec.len(), 1);
assert_eq!(vec.swap_remove(0), Some(5));
assert_eq!(vec.len(), 0);
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment