Skip to content

Commit ff1cd39

Browse files
committed
patch 8.2.1368: 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 <, !=, etc.
1 parent b4caa16 commit ff1cd39

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

src/eval.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
24222422
* var1 isnot var2
24232423
*
24242424
* "arg" must point to the first non-white of the expression.
2425-
* "arg" is advanced to the next non-white after the recognized expression.
2425+
* "arg" is advanced to just after the recognized expression.
24262426
*
24272427
* Return OK or FAIL.
24282428
*/
@@ -2452,9 +2452,17 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
24522452
typval_T var2;
24532453
int ic;
24542454
int vim9script = in_vim9script();
2455+
int evaluate = evalarg == NULL
2456+
? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
24552457

24562458
if (getnext)
24572459
*arg = eval_next_line(evalarg);
2460+
else if (evaluate && vim9script && !VIM_ISWHITE(**arg))
2461+
{
2462+
error_white_both(p, len);
2463+
clear_tv(rettv);
2464+
return FAIL;
2465+
}
24582466

24592467
if (vim9script && type_is && (p[len] == '?' || p[len] == '#'))
24602468
{
@@ -2482,13 +2490,19 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
24822490
/*
24832491
* Get the second variable.
24842492
*/
2493+
if (evaluate && vim9script && !IS_WHITE_OR_NUL(p[len]))
2494+
{
2495+
error_white_both(p, 1);
2496+
clear_tv(rettv);
2497+
return FAIL;
2498+
}
24852499
*arg = skipwhite_and_linebreak(p + len, evalarg);
24862500
if (eval5(arg, &var2, evalarg) == FAIL)
24872501
{
24882502
clear_tv(rettv);
24892503
return FAIL;
24902504
}
2491-
if (evalarg != NULL && (evalarg->eval_flags & EVAL_EVALUATE))
2505+
if (evaluate)
24922506
{
24932507
int ret;
24942508

@@ -2552,7 +2566,7 @@ eval_addlist(typval_T *tv1, typval_T *tv2)
25522566
* .. string concatenation
25532567
*
25542568
* "arg" must point to the first non-white of the expression.
2555-
* "arg" is advanced to the next non-white after the recognized expression.
2569+
* "arg" is advanced to just after the recognized expression.
25562570
*
25572571
* Return OK or FAIL.
25582572
*/
@@ -2754,7 +2768,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
27542768
* % number modulo
27552769
*
27562770
* "arg" must point to the first non-white of the expression.
2757-
* "arg" is advanced to the next non-white after the recognized expression.
2771+
* "arg" is advanced to just after the recognized expression.
27582772
*
27592773
* Return OK or FAIL.
27602774
*/
@@ -2956,7 +2970,7 @@ eval6(
29562970
* trailing ->name() method call
29572971
*
29582972
* "arg" must point to the first non-white of the expression.
2959-
* "arg" is advanced to the next non-white after the recognized expression.
2973+
* "arg" is advanced to just after the recognized expression.
29602974
*
29612975
* Return OK or FAIL.
29622976
*/

src/testdir/test_vim9_expr.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,38 @@ def Test_expr4_vimscript()
726726
set noignorecase
727727
END
728728
CheckScriptSuccess(lines)
729+
730+
# check missing white space
731+
lines =<< trim END
732+
vim9script
733+
echo 2>3
734+
END
735+
CheckScriptFailure(lines, 'E1004:')
736+
lines =<< trim END
737+
vim9script
738+
echo 2 >3
739+
END
740+
CheckScriptFailure(lines, 'E1004:')
741+
lines =<< trim END
742+
vim9script
743+
echo 2> 3
744+
END
745+
CheckScriptFailure(lines, 'E1004:')
746+
lines =<< trim END
747+
vim9script
748+
echo 2!=3
749+
END
750+
CheckScriptFailure(lines, 'E1004:')
751+
lines =<< trim END
752+
vim9script
753+
echo 2 !=3
754+
END
755+
CheckScriptFailure(lines, 'E1004:')
756+
lines =<< trim END
757+
vim9script
758+
echo 2!= 3
759+
END
760+
CheckScriptFailure(lines, 'E1004:')
729761
enddef
730762

731763
func Test_expr4_fails()

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+
1368,
757759
/**/
758760
1367,
759761
/**/

0 commit comments

Comments
 (0)