Skip to content

Commit b4caa16

Browse files
committed
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 %.
1 parent a629620 commit b4caa16

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

src/eval.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,13 +2586,14 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
25862586
break;
25872587

25882588
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
2589+
oplen = (concat && p[1] == '.') ? 2 : 1;
25892590
if (getnext)
25902591
*arg = eval_next_line(evalarg);
25912592
else
25922593
{
25932594
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
25942595
{
2595-
error_white_both(p, 1);
2596+
error_white_both(p, oplen);
25962597
clear_tv(rettv);
25972598
return FAIL;
25982599
}
@@ -2622,7 +2623,6 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
26222623
/*
26232624
* Get the second variable.
26242625
*/
2625-
oplen = (op == '.' && *(*arg + 1) == '.') ? 2 : 1;
26262626
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen]))
26272627
{
26282628
error_white_both(p, oplen);
@@ -2796,17 +2796,25 @@ eval6(
27962796
if (op != '*' && op != '/' && op != '%')
27972797
break;
27982798

2799+
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
27992800
if (getnext)
28002801
*arg = eval_next_line(evalarg);
28012802
else
2803+
{
2804+
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
2805+
{
2806+
error_white_both(p, 1);
2807+
clear_tv(rettv);
2808+
return FAIL;
2809+
}
28022810
*arg = p;
2811+
}
28032812

28042813
#ifdef FEAT_FLOAT
28052814
f1 = 0;
28062815
f2 = 0;
28072816
#endif
28082817
error = FALSE;
2809-
evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
28102818
if (evaluate)
28112819
{
28122820
#ifdef FEAT_FLOAT
@@ -2829,7 +2837,13 @@ eval6(
28292837
/*
28302838
* Get the second variable.
28312839
*/
2832-
*arg = skipwhite(*arg + 1);
2840+
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
2841+
{
2842+
error_white_both(p, 1);
2843+
clear_tv(rettv);
2844+
return FAIL;
2845+
}
2846+
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
28332847
if (eval7(arg, &var2, evalarg, FALSE) == FAIL)
28342848
return FAIL;
28352849

src/testdir/test_vim9_expr.vim

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,15 @@ def Test_expr5_vim9script()
841841
END
842842
CheckScriptSuccess(lines)
843843

844+
lines =<< trim END
845+
vim9script
846+
let var = 11 +
847+
77 -
848+
22
849+
assert_equal(66, var)
850+
END
851+
CheckScriptSuccess(lines)
852+
844853
lines =<< trim END
845854
vim9script
846855
let var = 'one'
@@ -999,7 +1008,7 @@ def Test_expr6()
9991008
enddef
10001009

10011010
def Test_expr6_vim9script()
1002-
# only checks line continuation
1011+
# check line continuation
10031012
let lines =<< trim END
10041013
vim9script
10051014
let var = 11
@@ -1016,6 +1025,32 @@ def Test_expr6_vim9script()
10161025
assert_equal(5, var)
10171026
END
10181027
CheckScriptSuccess(lines)
1028+
1029+
lines =<< trim END
1030+
vim9script
1031+
let var = 11 *
1032+
22 /
1033+
3
1034+
assert_equal(80, var)
1035+
END
1036+
CheckScriptSuccess(lines)
1037+
1038+
# check white space
1039+
lines =<< trim END
1040+
vim9script
1041+
echo 5*6
1042+
END
1043+
CheckScriptFailure(lines, 'E1004:')
1044+
lines =<< trim END
1045+
vim9script
1046+
echo 5 *6
1047+
END
1048+
CheckScriptFailure(lines, 'E1004:')
1049+
lines =<< trim END
1050+
vim9script
1051+
echo 5* 6
1052+
END
1053+
CheckScriptFailure(lines, 'E1004:')
10191054
enddef
10201055

10211056
def Test_expr6_float()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1367,
757759
/**/
758760
1366,
759761
/**/

0 commit comments

Comments
 (0)