Patch 8.2.1731
Problem: Vim9: cannot use += to append to empty NULL list.
Solution: Copy the list instead of extending it. (closes #6998)
Files: src/eval.c, src/testdir/test_vim9_assign.vim
*** ../vim-8.2.1730/src/eval.c 2020-09-16 21:08:23.642361197 +0200
--- src/eval.c 2020-09-23 15:55:17.297095646 +0200
***************
*** 872,879 ****
while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
{
if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
! && !(lp->ll_tv->v_type == VAR_DICT
! && lp->ll_tv->vval.v_dict != NULL)
&& !(lp->ll_tv->v_type == VAR_BLOB
&& lp->ll_tv->vval.v_blob != NULL))
{
--- 872,878 ----
while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
{
if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
! && !(lp->ll_tv->v_type == VAR_DICT)
&& !(lp->ll_tv->v_type == VAR_BLOB
&& lp->ll_tv->vval.v_blob != NULL))
{
***************
*** 994,1000 ****
--- 993,1012 ----
}
}
lp->ll_list = NULL;
+
+ // a NULL dict is equivalent with an empty dict
+ if (lp->ll_tv->vval.v_dict == NULL)
+ {
+ lp->ll_tv->vval.v_dict = dict_alloc();
+ if (lp->ll_tv->vval.v_dict == NULL)
+ {
+ clear_tv(&var1);
+ return NULL;
+ }
+ ++lp->ll_tv->vval.v_dict->dv_refcount;
+ }
lp->ll_dict = lp->ll_tv->vval.v_dict;
+
lp->ll_di = dict_find(lp->ll_dict, key, len);
// When assigning to a scope dictionary check that a function and
***************
*** 1460,1467 ****
if (*op != '+' || tv2->v_type != VAR_LIST)
break;
// List += List
! if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
! list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
return OK;
case VAR_NUMBER:
--- 1472,1487 ----
if (*op != '+' || tv2->v_type != VAR_LIST)
break;
// List += List
! if (tv2->vval.v_list != NULL)
! {
! if (tv1->vval.v_list == NULL)
! {
! tv1->vval.v_list = tv2->vval.v_list;
! ++tv1->vval.v_list->lv_refcount;
! }
! else
! list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
! }
return OK;
case VAR_NUMBER:
*** ../vim-8.2.1730/src/testdir/test_vim9_assign.vim 2020-09-23
13:25:28.398827624 +0200
--- src/testdir/test_vim9_assign.vim 2020-09-23 15:47:30.479674767 +0200
***************
*** 223,228 ****
--- 223,242 ----
endif
enddef
+ def Test_extend_list()
+ let lines =<< trim END
+ vim9script
+ let l: list<number>
+ l += [123]
+ assert_equal([123], l)
+
+ let d: dict<number>
+ d['one'] = 1
+ assert_equal(#{one: 1}, d)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
def Test_single_letter_vars()
# single letter variables
let a: number = 123
*** ../vim-8.2.1730/src/version.c 2020-09-23 13:25:28.398827624 +0200
--- src/version.c 2020-09-23 13:45:02.812702427 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1731,
/**/
--
Scientists decoded the first message from an alien civilization:
SIMPLY SEND 6 TIMES 10 TO THE 50 ATOMS OF HYDROGEN TO THE STAR
SYSTEM AT THE TOP OF THE LIST, CROSS OFF THAT STAR SYSTEM, THEN PUT
YOUR STAR SYSTEM AT THE BOTTOM OF THE LIST AND SEND IT TO 100 OTHER
STAR SYSTEMS. WITHIN ONE TENTH GALACTIC ROTATION YOU WILL RECEIVE
ENOUGH HYDROGREN TO POWER YOUR CIVILIZATION UNTIL ENTROPY REACHES ITS
MAXIMUM! IT REALLY WORKS!
/// 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/202009231357.08NDvEDO3928136%40masaka.moolenaar.net.