Fix bug in Array::insert.

This commit is contained in:
Stephen Chung 2021-01-29 22:29:36 +08:00
parent 903b6d6795
commit bb925a697c
2 changed files with 9 additions and 8 deletions

View File

@ -8,19 +8,20 @@ This version streamlines compiling for WASM.
Rust compiler minimum version is raised to 1.49. Rust compiler minimum version is raised to 1.49.
Breaking changes
----------------
* Rust compiler requirement raised to 1.49.
* `NativeCallContext::new` taker an additional parameter containing the name of the function called.
* `Engine::set_doc_comments` is renamed `Engine::enable_doc_comments`.
Bug fixes Bug fixes
--------- ---------
* Parameters passed to plugin module functions were sometimes erroneously consumed. This is now fixed. * Parameters passed to plugin module functions were sometimes erroneously consumed. This is now fixed.
* Fixes compilation errors in `metadata` feature build. * Fixes compilation errors in `metadata` feature build.
* Stacking `!` operators now work properly. * Stacking `!` operators now work properly.
* Off-by-one error in `insert` method for arrays is fixed.
Breaking changes
----------------
* Rust compiler requirement raised to 1.49.
* `NativeCallContext::new` taker an additional parameter containing the name of the function called.
* `Engine::set_doc_comments` is renamed `Engine::enable_doc_comments`.
New features New features
------------ ------------

View File

@ -29,7 +29,7 @@ macro_rules! gen_array_functions {
pub fn insert(list: &mut Array, position: INT, item: $arg_type) { pub fn insert(list: &mut Array, position: INT, item: $arg_type) {
if position <= 0 { if position <= 0 {
list.insert(0, Dynamic::from(item)); list.insert(0, Dynamic::from(item));
} else if (position as usize) >= list.len() - 1 { } else if (position as usize) >= list.len() {
push(list, item); push(list, item);
} else { } else {
list.insert(position as usize, Dynamic::from(item)); list.insert(position as usize, Dynamic::from(item));