0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3111: Vim9: confusing error with extra whitespace before colon

Problem:    Vim9: confusing error with extra whitespace before colon.
Solution:   Check for colon after white space. (closes #8513)
This commit is contained in:
Bram Moolenaar
2021-07-05 21:41:48 +02:00
parent 04db26b360
commit 404557e6a6
4 changed files with 22 additions and 5 deletions

View File

@@ -1660,6 +1660,7 @@ eval_for_line(
evalarg_T *evalarg) evalarg_T *evalarg)
{ {
forinfo_T *fi; forinfo_T *fi;
char_u *var_list_end;
char_u *expr; char_u *expr;
typval_T tv; typval_T tv;
list_T *l; list_T *l;
@@ -1671,14 +1672,18 @@ eval_for_line(
if (fi == NULL) if (fi == NULL)
return NULL; return NULL;
expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE); var_list_end = skip_var_list(arg, TRUE, &fi->fi_varcount,
if (expr == NULL) &fi->fi_semicolon, FALSE);
if (var_list_end == NULL)
return fi; return fi;
expr = skipwhite_and_linebreak(expr, evalarg); expr = skipwhite_and_linebreak(var_list_end, evalarg);
if (expr[0] != 'i' || expr[1] != 'n' if (expr[0] != 'i' || expr[1] != 'n'
|| !(expr[2] == NUL || VIM_ISWHITE(expr[2]))) || !(expr[2] == NUL || VIM_ISWHITE(expr[2])))
{ {
if (in_vim9script() && *expr == ':' && expr != var_list_end)
semsg(_(e_no_white_space_allowed_before_colon_str), expr);
else
emsg(_(e_missing_in)); emsg(_(e_missing_in));
return fi; return fi;
} }

View File

@@ -2566,6 +2566,13 @@ def Test_for_loop_fails()
endfor endfor
END END
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) 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 enddef
def Test_for_loop_script_var() def Test_for_loop_script_var()

View File

@@ -755,6 +755,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 */
/**/
3111,
/**/ /**/
3110, 3110,
/**/ /**/

View File

@@ -7775,6 +7775,9 @@ compile_for(char_u *arg_start, cctx_T *cctx)
return NULL; return NULL;
if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2])) if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
{ {
if (*p == ':' && wp != p)
semsg(_(e_no_white_space_allowed_before_colon_str), p);
else
emsg(_(e_missing_in)); emsg(_(e_missing_in));
return NULL; return NULL;
} }