mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:8.2.3336: behavior of negative index in list change changed
Problem: Behavior of negative index in list change changed. (Naruhiko
Nishino)
Solution: Only change it for Vim9 script. (closes vim/vim#8749)
92f05f21af
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -787,15 +787,15 @@ int tv_list_slice_or_index(list_T *list, bool range, int n1_arg, int n2_arg, typ
|
|||||||
n1 = len + n1;
|
n1 = len + n1;
|
||||||
}
|
}
|
||||||
if (n1 < 0 || n1 >= len) {
|
if (n1 < 0 || n1 >= len) {
|
||||||
// For a range we allow invalid values and return an empty
|
// For a range we allow invalid values and return an empty list.
|
||||||
// list. A list index out of range is an error.
|
// A list index out of range is an error.
|
||||||
if (!range) {
|
if (!range) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
semsg(_(e_listidx), (int64_t)n1);
|
semsg(_(e_listidx), (int64_t)n1);
|
||||||
}
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
n1 = n1 < 0 ? 0 : len;
|
n1 = len;
|
||||||
}
|
}
|
||||||
if (range) {
|
if (range) {
|
||||||
if (n2 < 0) {
|
if (n2 < 0) {
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
" Tests for the List and Dict types
|
" Tests for the List and Dict types
|
||||||
|
|
||||||
|
source vim9.vim
|
||||||
|
|
||||||
func TearDown()
|
func TearDown()
|
||||||
" Run garbage collection after every test
|
" Run garbage collection after every test
|
||||||
call test_garbagecollect_now()
|
call test_garbagecollect_now()
|
||||||
@@ -37,6 +39,23 @@ func Test_list_slice()
|
|||||||
let l[:1] += [1, 2]
|
let l[:1] += [1, 2]
|
||||||
let l[2:] -= [1]
|
let l[2:] -= [1]
|
||||||
call assert_equal([2, 4, 2], l)
|
call assert_equal([2, 4, 2], l)
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
VAR l = [1, 2]
|
||||||
|
call assert_equal([1, 2], l[:])
|
||||||
|
call assert_equal([2], l[-1 : -1])
|
||||||
|
call assert_equal([1, 2], l[-2 : -1])
|
||||||
|
END
|
||||||
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
let l = [1, 2]
|
||||||
|
call assert_equal([], l[-3 : -1])
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
var l = [1, 2]
|
||||||
|
assert_equal([1, 2], l[-3 : -1])
|
||||||
|
END
|
||||||
|
call CheckDefAndScriptSuccess(lines)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" List identity
|
" List identity
|
||||||
|
Reference in New Issue
Block a user