0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.3113: no error when for loop variable shadows script variable

Problem:    No error when for loop variable shadows script variable.
Solution:   Check for the error. (closes #8512)
This commit is contained in:
Bram Moolenaar
2021-07-05 22:23:00 +02:00
parent 5cb09620c1
commit 442b29c968
3 changed files with 14 additions and 7 deletions

View File

@@ -1777,7 +1777,10 @@ next_for_item(void *fi_void, char_u *arg)
forinfo_T *fi = (forinfo_T *)fi_void;
int result;
int flag = ASSIGN_FOR_LOOP | (in_vim9script()
? (ASSIGN_FINAL | ASSIGN_DECL | ASSIGN_NO_MEMBER_TYPE)
? (ASSIGN_FINAL
// first round: error if variable exists
| (fi->fi_bi == 0 ? 0 : ASSIGN_DECL)
| ASSIGN_NO_MEMBER_TYPE)
: 0);
listitem_T *item;
@@ -1807,6 +1810,7 @@ next_for_item(void *fi_void, char_u *arg)
tv.v_lock = VAR_FIXED;
tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len);
fi->fi_byte_idx += len;
++fi->fi_bi;
result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
fi->fi_varcount, flag, NULL) == OK;
vim_free(tv.vval.v_string);
@@ -1819,6 +1823,7 @@ next_for_item(void *fi_void, char_u *arg)
else
{
fi->fi_lw.lw_item = item->li_next;
++fi->fi_bi;
result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
fi->fi_varcount, flag, NULL) == OK);
}