mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.3649: Vim9: error for variable declared in while loop
Problem: Vim9: error for variable declared in while loop. Solution: Do not keep the first variable. (closes #9191)
This commit is contained in:
@@ -1201,9 +1201,10 @@ ex_while(exarg_T *eap)
|
|||||||
& CSF_FUNC_DEF;
|
& CSF_FUNC_DEF;
|
||||||
|
|
||||||
// Any variables defined in the previous round are no longer
|
// Any variables defined in the previous round are no longer
|
||||||
// visible. Keep the first one, it is the loop variable that
|
// visible. Keep the first one for ":for", it is the loop
|
||||||
// we reuse every time around.
|
// variable that we reuse every time around.
|
||||||
for (i = cstack->cs_script_var_len[cstack->cs_idx] + 1;
|
for (i = cstack->cs_script_var_len[cstack->cs_idx]
|
||||||
|
+ (eap->cmdidx == CMD_while ? 0 : 1);
|
||||||
i < si->sn_var_vals.ga_len; ++i)
|
i < si->sn_var_vals.ga_len; ++i)
|
||||||
{
|
{
|
||||||
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
|
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
|
||||||
|
@@ -3083,6 +3083,21 @@ def Test_while_loop()
|
|||||||
endwhile
|
endwhile
|
||||||
enddef
|
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()
|
def Test_while_loop_fails()
|
||||||
CheckDefFailure(['while xxx'], 'E1001:')
|
CheckDefFailure(['while xxx'], 'E1001:')
|
||||||
CheckDefFailure(['endwhile'], 'E588:')
|
CheckDefFailure(['endwhile'], 'E588:')
|
||||||
|
@@ -757,6 +757,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3649,
|
||||||
/**/
|
/**/
|
||||||
3648,
|
3648,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user