Patch 8.2.3336
Problem: Behavior of negative index in list change changed. (Naruhiko
Nishino)
Solution: Only change it for Vim9 script. (closes #8749)
Files: src/list.c, src/testdir/test_listdict.vim
*** ../vim-8.2.3335/src/list.c 2021-08-12 19:27:46.458459623 +0200
--- src/list.c 2021-08-12 21:12:27.583209440 +0200
***************
*** 1146,1160 ****
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.
if (!range)
{
if (verbose)
semsg(_(e_listidx), (long)n1_arg);
return FAIL;
}
! n1 = n1 < 0 ? 0 : len;
}
if (range)
{
--- 1146,1164 ----
n1 = len + n1;
if (n1 < 0 || n1 >= len)
{
! // For a range we allow invalid values and for legacy script return an
! // empty list, for Vim9 script start at the first item.
! // A list index out of range is an error.
if (!range)
{
if (verbose)
semsg(_(e_listidx), (long)n1_arg);
return FAIL;
}
! if (in_vim9script())
! n1 = n1 < 0 ? 0 : len;
! else
! n1 = len;
}
if (range)
{
*** ../vim-8.2.3335/src/testdir/test_listdict.vim 2021-08-12
19:27:46.458459623 +0200
--- src/testdir/test_listdict.vim 2021-08-12 21:10:28.255525986 +0200
***************
*** 42,47 ****
--- 42,64 ----
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
*** ../vim-8.2.3335/src/version.c 2021-08-12 19:27:46.458459623 +0200
--- src/version.c 2021-08-12 21:11:30.699358605 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3336,
/**/
--
ARTHUR: Ni!
BEDEVERE: Nu!
ARTHUR: No. Ni! More like this. "Ni"!
BEDEVERE: Ni, ni, ni!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202108121915.17CJFtsk3293924%40masaka.moolenaar.net.