Problem: Vim9: getting a list member may not work.
Solution: Clear the list only after copying the item. (closes #6393)
call CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list')
enddef
+def Test_expr_index()
+ # getting the one member should clear the list only after getting the item
+ assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1])
+enddef
+
def Test_expr_member_vim9script()
let lines =<< trim END
vim9script
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1134,
/**/
1133,
/**/
list_T *list;
varnumber_T n;
listitem_T *li;
+ typval_T temp_tv;
// list index: list is at stack-2, index at stack-1
tv = STACK_TV_BOT(-2);
goto failed;
}
--ectx.ec_stack.ga_len;
- clear_tv(STACK_TV_BOT(-1));
- copy_tv(&li->li_tv, STACK_TV_BOT(-1));
+ // Clear the list after getting the item, to avoid that it
+ // make the item invalid.
+ tv = STACK_TV_BOT(-1);
+ temp_tv = *tv;
+ copy_tv(&li->li_tv, tv);
+ clear_tv(&temp_tv);
}
break;