summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-05 21:41:48 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-05 21:41:48 +0200
commit404557e6a60389d09bbf91dd0cf3bae11bd623b9 (patch)
treee3d420c3f30df3d972734c35d90c4c22ac339701
parent04db26b36000a4677b95403ec94bd11f6cc73975 (diff)
patch 8.2.3111: Vim9: confusing error with extra whitespace before colonv8.2.3111
Problem: Vim9: confusing error with extra whitespace before colon. Solution: Check for colon after white space. (closes #8513)
-rw-r--r--src/eval.c13
-rw-r--r--src/testdir/test_vim9_script.vim7
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c5
4 files changed, 22 insertions, 5 deletions
diff --git a/src/eval.c b/src/eval.c
index f57001647c..1a84d2c1f5 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1660,6 +1660,7 @@ eval_for_line(
evalarg_T *evalarg)
{
forinfo_T *fi;
+ char_u *var_list_end;
char_u *expr;
typval_T tv;
list_T *l;
@@ -1671,15 +1672,19 @@ eval_for_line(
if (fi == NULL)
return NULL;
- expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE);
- if (expr == NULL)
+ var_list_end = skip_var_list(arg, TRUE, &fi->fi_varcount,
+ &fi->fi_semicolon, FALSE);
+ if (var_list_end == NULL)
return fi;
- expr = skipwhite_and_linebreak(expr, evalarg);
+ expr = skipwhite_and_linebreak(var_list_end, evalarg);
if (expr[0] != 'i' || expr[1] != 'n'
|| !(expr[2] == NUL || VIM_ISWHITE(expr[2])))
{
- emsg(_(e_missing_in));
+ if (in_vim9script() && *expr == ':' && expr != var_list_end)
+ semsg(_(e_no_white_space_allowed_before_colon_str), expr);
+ else
+ emsg(_(e_missing_in));
return fi;
}
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 9cf098917c..9d54899a66 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2566,6 +2566,13 @@ def Test_for_loop_fails()
endfor
END
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
+
+ lines =<< trim END
+ for n : number in [1, 2]
+ echo n
+ endfor
+ END
+ CheckDefAndScriptFailure(lines, 'E1059:', 1)
enddef
def Test_for_loop_script_var()
diff --git a/src/version.c b/src/version.c
index b448822d5a..0653c2797c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3111,
+/**/
3110,
/**/
3109,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 9569f2f4d3..d630736764 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -7775,7 +7775,10 @@ compile_for(char_u *arg_start, cctx_T *cctx)
return NULL;
if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
{
- emsg(_(e_missing_in));
+ if (*p == ':' && wp != p)
+ semsg(_(e_no_white_space_allowed_before_colon_str), p);
+ else
+ emsg(_(e_missing_in));
return NULL;
}
wp = p + 2;