summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-02 13:23:36 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-02 13:23:36 +0100
commit38bd8de551225bfca133805f21cee2592f0c759d (patch)
tree4293eb434685f90f7926a612bfdd3181be8fbd75
parent1cbfc9914db1cb06aaa092fa42eb7a2fc3dc7ad7 (diff)
downloadvim-git-38bd8de551225bfca133805f21cee2592f0c759d.tar.gz
patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"v8.2.2079
Problem: Vim9: cannot put a linebreak before or after "in" of ":for". Solution: Skip over linebreak.
-rw-r--r--src/testdir/test_vim9_script.vim22
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c11
3 files changed, 33 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index a18e3f2a4..01396967f 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1849,6 +1849,28 @@ def Test_for_loop()
concat ..= str
endfor
assert_equal('onetwo', concat)
+
+ var total = 0
+ for nr in
+ [1, 2, 3]
+ total += nr
+ endfor
+ assert_equal(6, total)
+
+ total = 0
+ for nr
+ in [1, 2, 3]
+ total += nr
+ endfor
+ assert_equal(6, total)
+
+ total = 0
+ for nr
+ in
+ [1, 2, 3]
+ total += nr
+ endfor
+ assert_equal(6, total)
enddef
def Test_for_loop_fails()
diff --git a/src/version.c b/src/version.c
index 2eb5de5fc..3a2058112 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2079,
+/**/
2078,
/**/
2077,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 7712c001c..07a22daa0 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -6486,6 +6486,7 @@ compile_for(char_u *arg_start, cctx_T *cctx)
char_u *arg_end;
char_u *name = NULL;
char_u *p;
+ char_u *wp;
int var_count = 0;
int semicolon = FALSE;
size_t varlen;
@@ -6503,13 +6504,19 @@ compile_for(char_u *arg_start, cctx_T *cctx)
var_count = 1;
// consume "in"
+ wp = p;
p = skipwhite(p);
- if (STRNCMP(p, "in", 2) != 0 || !VIM_ISWHITE(p[2]))
+ if (may_get_next_line_error(wp, &p, cctx) == FAIL)
+ return NULL;
+ if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
{
emsg(_(e_missing_in));
return NULL;
}
- p = skipwhite(p + 2);
+ wp = p + 2;
+ p = skipwhite(wp);
+ if (may_get_next_line_error(wp, &p, cctx) == FAIL)
+ return NULL;
scope = new_scope(cctx, FOR_SCOPE);
if (scope == NULL)