diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-05-04 16:12:52 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-05-04 16:14:43 +0800 |
commit | 47132823ab1c4f458c945df89d12e897d77db8a8 (patch) | |
tree | f71b8841ee2b9bd0e7a51e184a64d3117f51cc3d | |
parent | 7ac63906eae92b5d31fc7e380ef05b8bce73ad8b (diff) | |
download | rneovim-47132823ab1c4f458c945df89d12e897d77db8a8.tar.gz rneovim-47132823ab1c4f458c945df89d12e897d77db8a8.tar.bz2 rneovim-47132823ab1c4f458c945df89d12e897d77db8a8.zip |
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)
https://github.com/vim/vim/commit/92f05f21afdb8a43581554a252cb2fc050f9e03b
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/eval/typval.c | 6 | ||||
-rw-r--r-- | test/old/testdir/test_listdict.vim | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 8028688ac8..0b2be3074f 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -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; } if (n1 < 0 || n1 >= len) { - // For a range we allow invalid values and return an empty - // list. A list index out of range is an error. + // For a range we allow invalid values and return an empty list. + // A list index out of range is an error. if (!range) { if (verbose) { semsg(_(e_listidx), (int64_t)n1); } return FAIL; } - n1 = n1 < 0 ? 0 : len; + n1 = len; } if (range) { if (n2 < 0) { diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim index 0ff3582da9..11dade18f3 100644 --- a/test/old/testdir/test_listdict.vim +++ b/test/old/testdir/test_listdict.vim @@ -1,5 +1,7 @@ " Tests for the List and Dict types +source vim9.vim + func TearDown() " Run garbage collection after every test call test_garbagecollect_now() @@ -37,6 +39,23 @@ func Test_list_slice() let l[:1] += [1, 2] let l[2:] -= [1] 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 " List identity |