Patch 8.2.1821
Problem: Vim9: concatenating to a NULL list doesn't work.
Solution: Handle a NULL list like an empty list. (closes #7064)
Files: src/list.c, src/testdir/test_vim9_assign.vim
*** ../vim-8.2.1820/src/list.c 2020-09-16 23:23:33.026882158 +0200
--- src/list.c 2020-10-10 15:35:05.046678599 +0200
***************
*** 824,830 ****
}
/*
! * Extend "l1" with "l2".
* If "bef" is NULL append at the end, otherwise insert before this item.
* Returns FAIL when out of memory.
*/
--- 824,830 ----
}
/*
! * Extend "l1" with "l2". "l1" must not be NULL.
* If "bef" is NULL append at the end, otherwise insert before this item.
* Returns FAIL when out of memory.
*/
***************
*** 832,839 ****
list_extend(list_T *l1, list_T *l2, listitem_T *bef)
{
listitem_T *item;
! int todo = l2->lv_len;
CHECK_LIST_MATERIALIZE(l1);
CHECK_LIST_MATERIALIZE(l2);
--- 832,844 ----
list_extend(list_T *l1, list_T *l2, listitem_T *bef)
{
listitem_T *item;
! int todo;
+ // NULL list is equivalent to an empty list: nothing to do.
+ if (l2 == NULL || l2->lv_len == 0)
+ return OK;
+
+ todo = l2->lv_len;
CHECK_LIST_MATERIALIZE(l1);
CHECK_LIST_MATERIALIZE(l2);
***************
*** 854,868 ****
{
list_T *l;
- if (l1 == NULL || l2 == NULL)
- return FAIL;
-
// make a copy of the first list.
! l = list_copy(l1, FALSE, 0);
if (l == NULL)
return FAIL;
tv->v_type = VAR_LIST;
tv->vval.v_list = l;
// append all items from the second list
return list_extend(l, l2, NULL);
--- 859,875 ----
{
list_T *l;
// make a copy of the first list.
! if (l1 == NULL)
! l = list_alloc();
! else
! l = list_copy(l1, FALSE, 0);
if (l == NULL)
return FAIL;
tv->v_type = VAR_LIST;
tv->vval.v_list = l;
+ if (l1 == NULL)
+ ++l->lv_refcount;
// append all items from the second list
return list_extend(l, l2, NULL);
*** ../vim-8.2.1820/src/testdir/test_vim9_assign.vim 2020-10-03
22:51:42.894813399 +0200
--- src/testdir/test_vim9_assign.vim 2020-10-10 15:31:39.415142100 +0200
***************
*** 236,241 ****
--- 236,253 ----
assert_equal(#{one: 1}, d)
END
CheckScriptSuccess(lines)
+
+ # appending to NULL list from a function
+ lines =<< trim END
+ vim9script
+ var list: list<string>
+ def Func()
+ list += ['a', 'b']
+ enddef
+ Func()
+ assert_equal(['a', 'b'], list)
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_single_letter_vars()
*** ../vim-8.2.1820/src/version.c 2020-10-10 15:05:19.970305397 +0200
--- src/version.c 2020-10-10 15:22:25.148112016 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1821,
/**/
--
ERROR 047: Keyboard not found. Press RETURN to continue.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ 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/202010101338.09ADccia3723376%40masaka.moolenaar.net.