Patch 8.2.3649

1 view
Skip to first unread message

Bram Moolenaar

unread,
Nov 22, 2021, 1:31:43 PM11/22/21
to vim...@googlegroups.com

Patch 8.2.3649
Problem: Vim9: error for variable declared in while loop.
Solution: Do not keep the first variable. (closes #9191)
Files: src/ex_eval.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.3648/src/ex_eval.c 2021-11-22 15:05:42.713617025 +0000
--- src/ex_eval.c 2021-11-22 18:21:38.976602296 +0000
***************
*** 1201,1209 ****
& CSF_FUNC_DEF;

// Any variables defined in the previous round are no longer
! // visible. Keep the first one, it is the loop variable that
! // we reuse every time around.
! for (i = cstack->cs_script_var_len[cstack->cs_idx] + 1;
i < si->sn_var_vals.ga_len; ++i)
{
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
--- 1201,1210 ----
& CSF_FUNC_DEF;

// Any variables defined in the previous round are no longer
! // visible. Keep the first one for ":for", it is the loop
! // variable that we reuse every time around.
! for (i = cstack->cs_script_var_len[cstack->cs_idx]
! + (eap->cmdidx == CMD_while ? 0 : 1);
i < si->sn_var_vals.ga_len; ++i)
{
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
*** ../vim-8.2.3648/src/testdir/test_vim9_script.vim 2021-11-21 11:35:59.460938795 +0000
--- src/testdir/test_vim9_script.vim 2021-11-22 18:20:37.016672820 +0000
***************
*** 3083,3088 ****
--- 3083,3103 ----
endwhile
enddef

+ def Test_while_loop_in_script()
+ var lines =<< trim END
+ vim9script
+ var result = ''
+ var cnt = 0
+ while cnt < 3
+ var s = 'v' .. cnt
+ result ..= s
+ cnt += 1
+ endwhile
+ assert_equal('v0v1v2', result)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
def Test_while_loop_fails()
CheckDefFailure(['while xxx'], 'E1001:')
CheckDefFailure(['endwhile'], 'E588:')
*** ../vim-8.2.3648/src/version.c 2021-11-22 17:21:44.853760423 +0000
--- src/version.c 2021-11-22 18:20:51.072656894 +0000
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 3649,
/**/

--
Permission is granted to read this message out aloud on Kings Cross Road,
London, under the condition that the orator is properly dressed.

/// 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