diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-07-18 17:08:50 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-18 17:08:50 +0200 |
commit | ad2d4969e1616d3a0354c181e3a09271d5433b3d (patch) | |
tree | acbefd48d05e7164b98ed9a69e2cb0ccd6d2c8ff /src/eval.c | |
parent | 0c35752d04f70408a3c560d5b3edbafcaddff302 (diff) | |
download | vim-git-ad2d4969e1616d3a0354c181e3a09271d5433b3d.tar.gz |
patch 8.2.3177: Vim9: can not use "for _ in expr" at script levelv8.2.3177
Problem: Vim9: can not use "for _ in expr" at script level.
Solution: Skip assignment if the loop variable is "_".
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 2e8ab3d8f..058b2d3be 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1784,6 +1784,8 @@ next_for_item(void *fi_void, char_u *arg) | ASSIGN_NO_MEMBER_TYPE) : 0); listitem_T *item; + int skip_assign = in_vim9script() && arg[0] == '_' + && !eval_isnamec(arg[1]); if (fi->fi_blob != NULL) { @@ -1795,6 +1797,8 @@ next_for_item(void *fi_void, char_u *arg) tv.v_lock = VAR_FIXED; tv.vval.v_number = blob_get(fi->fi_blob, fi->fi_bi); ++fi->fi_bi; + if (skip_assign) + return TRUE; return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon, fi->fi_varcount, flag, NULL) == OK; } @@ -1812,7 +1816,10 @@ next_for_item(void *fi_void, char_u *arg) 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, + if (skip_assign) + result = TRUE; + else + result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon, fi->fi_varcount, flag, NULL) == OK; vim_free(tv.vval.v_string); return result; @@ -1825,7 +1832,10 @@ next_for_item(void *fi_void, char_u *arg) { fi->fi_lw.lw_item = item->li_next; ++fi->fi_bi; - result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon, + if (skip_assign) + result = TRUE; + else + result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon, fi->fi_varcount, flag, NULL) == OK); } return result; |