Patch 8.2.3051

3 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 26, 2021, 6:41:38 AM6/26/21
to vim...@googlegroups.com

Patch 8.2.3051
Problem: Vim9: for loop with one list variable does not work.
Solution: Use a separate flag for unpacking a list. (closes #8452)
Files: src/vim9compile.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.3050/src/vim9compile.c 2021-06-25 21:31:03.379070659 +0200
--- src/vim9compile.c 2021-06-26 12:35:28.625487225 +0200
***************
*** 7731,7736 ****
--- 7731,7737 ----
char_u *p;
char_u *wp;
int var_count = 0;
+ int var_list = FALSE;
int semicolon = FALSE;
size_t varlen;
garray_T *stack = &cctx->ctx_type_stack;
***************
*** 7747,7752 ****
--- 7748,7755 ----
return NULL;
if (var_count == 0)
var_count = 1;
+ else
+ var_list = TRUE; // can also be a list of one variable

// consume "in"
wp = p;
***************
*** 7811,7817 ****
else if (vartype->tt_type == VAR_LIST
&& vartype->tt_member->tt_type != VAR_ANY)
{
! if (var_count == 1)
item_type = vartype->tt_member;
else if (vartype->tt_member->tt_type == VAR_LIST
&& vartype->tt_member->tt_member->tt_type != VAR_ANY)
--- 7814,7820 ----
else if (vartype->tt_type == VAR_LIST
&& vartype->tt_member->tt_type != VAR_ANY)
{
! if (!var_list)
item_type = vartype->tt_member;
else if (vartype->tt_member->tt_type == VAR_LIST
&& vartype->tt_member->tt_member->tt_type != VAR_ANY)
***************
*** 7828,7834 ****
generate_FOR(cctx, loop_lvar->lv_idx);

arg = arg_start;
! if (var_count > 1)
{
generate_UNPACK(cctx, var_count, semicolon);
arg = skipwhite(arg + 1); // skip white after '['
--- 7831,7837 ----
generate_FOR(cctx, loop_lvar->lv_idx);

arg = arg_start;
! if (var_list)
{
generate_UNPACK(cctx, var_count, semicolon);
arg = skipwhite(arg + 1); // skip white after '['
***************
*** 7899,7910 ****
}

// Reserve a variable to store "var".
! where.wt_index = var_count > 1 ? idx + 1 : 0;
where.wt_variable = TRUE;
if (lhs_type == &t_any)
lhs_type = item_type;
else if (item_type != &t_unknown
! && !(var_count > 1 && item_type == &t_any)
&& check_type(lhs_type, item_type, TRUE, where) == FAIL)
goto failed;
var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_type);
--- 7902,7913 ----
}

// Reserve a variable to store "var".
! where.wt_index = var_list ? idx + 1 : 0;
where.wt_variable = TRUE;
if (lhs_type == &t_any)
lhs_type = item_type;
else if (item_type != &t_unknown
! && !(var_list && item_type == &t_any)
&& check_type(lhs_type, item_type, TRUE, where) == FAIL)
goto failed;
var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_type);
*** ../vim-8.2.3050/src/testdir/test_vim9_script.vim 2021-06-20 12:40:05.342813034 +0200
--- src/testdir/test_vim9_script.vim 2021-06-26 12:38:37.061171813 +0200
***************
*** 2385,2390 ****
--- 2385,2397 ----
endfor
assert_equal('1a2b', res)

+ # unpack with one var
+ var reslist = []
+ for [x] in [['aaa'], ['bbb']]
+ reslist->add(x)
+ endfor
+ assert_equal(['aaa', 'bbb'], reslist)
+
# loop over string
res = ''
for c in 'aéc̀d'
*** ../vim-8.2.3050/src/version.c 2021-06-26 12:02:51.488571731 +0200
--- src/version.c 2021-06-26 12:40:32.600971634 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3051,
/**/

--
To define recursion, we must first define recursion.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages