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

patch 8.2.1367: Vim9: no error for missing white space around operator

Problem:    Vim9: no error for missing white space around operator.
Solution:   Check for white space around *, / and %.
This commit is contained in:
Bram Moolenaar
2020-08-05 11:36:52 +02:00
parent a6296200bd
commit b4caa163ff
3 changed files with 56 additions and 5 deletions

View File

@@ -2586,13 +2586,14 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
break; break;
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
oplen = (concat && p[1] == '.') ? 2 : 1;
if (getnext) if (getnext)
*arg = eval_next_line(evalarg); *arg = eval_next_line(evalarg);
else else
{ {
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg)) if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
{ {
error_white_both(p, 1); error_white_both(p, oplen);
clear_tv(rettv); clear_tv(rettv);
return FAIL; return FAIL;
} }
@@ -2622,7 +2623,6 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
/* /*
* Get the second variable. * Get the second variable.
*/ */
oplen = (op == '.' && *(*arg + 1) == '.') ? 2 : 1;
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen])) if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen]))
{ {
error_white_both(p, oplen); error_white_both(p, oplen);
@@ -2796,17 +2796,25 @@ eval6(
if (op != '*' && op != '/' && op != '%') if (op != '*' && op != '/' && op != '%')
break; break;
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
if (getnext) if (getnext)
*arg = eval_next_line(evalarg); *arg = eval_next_line(evalarg);
else else
{
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
{
error_white_both(p, 1);
clear_tv(rettv);
return FAIL;
}
*arg = p; *arg = p;
}
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
f1 = 0; f1 = 0;
f2 = 0; f2 = 0;
#endif #endif
error = FALSE; error = FALSE;
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
if (evaluate) if (evaluate)
{ {
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
@@ -2829,7 +2837,13 @@ eval6(
/* /*
* Get the second variable. * Get the second variable.
*/ */
*arg = skipwhite(*arg + 1); if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
{
error_white_both(p, 1);
clear_tv(rettv);
return FAIL;
}
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
if (eval7(arg, &var2, evalarg, FALSE) == FAIL) if (eval7(arg, &var2, evalarg, FALSE) == FAIL)
return FAIL; return FAIL;

View File

@@ -841,6 +841,15 @@ def Test_expr5_vim9script()
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
lines =<< trim END
vim9script
let var = 11 +
77 -
22
assert_equal(66, var)
END
CheckScriptSuccess(lines)
lines =<< trim END lines =<< trim END
vim9script vim9script
let var = 'one' let var = 'one'
@@ -999,7 +1008,7 @@ def Test_expr6()
enddef enddef
def Test_expr6_vim9script() def Test_expr6_vim9script()
# only checks line continuation # check line continuation
let lines =<< trim END let lines =<< trim END
vim9script vim9script
let var = 11 let var = 11
@@ -1016,6 +1025,32 @@ def Test_expr6_vim9script()
assert_equal(5, var) assert_equal(5, var)
END END
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
lines =<< trim END
vim9script
let var = 11 *
22 /
3
assert_equal(80, var)
END
CheckScriptSuccess(lines)
# check white space
lines =<< trim END
vim9script
echo 5*6
END
CheckScriptFailure(lines, 'E1004:')
lines =<< trim END
vim9script
echo 5 *6
END
CheckScriptFailure(lines, 'E1004:')
lines =<< trim END
vim9script
echo 5* 6
END
CheckScriptFailure(lines, 'E1004:')
enddef enddef
def Test_expr6_float() def Test_expr6_float()

View File

@@ -754,6 +754,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 */
/**/
1367,
/**/ /**/
1366, 1366,
/**/ /**/