Skip to content

Commit fdac71c

Browse files
committed
patch 8.2.1372: 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 3c1c9fd commit fdac71c

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

src/eval.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ eval0(
20722072
* expr2 ? expr1 : expr1
20732073
*
20742074
* "arg" must point to the first non-white of the expression.
2075-
* "arg" is advanced to the next non-white after the recognized expression.
2075+
* "arg" is advanced to just after the recognized expression.
20762076
*
20772077
* Note: "rettv.v_lock" is not set.
20782078
*
@@ -2111,7 +2111,15 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21112111
if (getnext)
21122112
*arg = eval_next_line(evalarg_used);
21132113
else
2114+
{
2115+
if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
2116+
{
2117+
error_white_both(p, 1);
2118+
clear_tv(rettv);
2119+
return FAIL;
2120+
}
21142121
*arg = p;
2122+
}
21152123

21162124
result = FALSE;
21172125
if (evaluate)
@@ -2128,6 +2136,12 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21282136
/*
21292137
* Get the second variable. Recursive!
21302138
*/
2139+
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
2140+
{
2141+
error_white_both(p, 1);
2142+
clear_tv(rettv);
2143+
return FAIL;
2144+
}
21312145
*arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
21322146
evalarg_used->eval_flags = result ? orig_flags
21332147
: orig_flags & ~EVAL_EVALUATE;
@@ -2148,11 +2162,25 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21482162
if (getnext)
21492163
*arg = eval_next_line(evalarg_used);
21502164
else
2165+
{
2166+
if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
2167+
{
2168+
error_white_both(p, 1);
2169+
clear_tv(rettv);
2170+
return FAIL;
2171+
}
21512172
*arg = p;
2173+
}
21522174

21532175
/*
21542176
* Get the third variable. Recursive!
21552177
*/
2178+
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
2179+
{
2180+
error_white_both(p, 1);
2181+
clear_tv(rettv);
2182+
return FAIL;
2183+
}
21562184
*arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
21572185
evalarg_used->eval_flags = !result ? orig_flags
21582186
: orig_flags & ~EVAL_EVALUATE;
@@ -2179,7 +2207,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21792207
* expr2 || expr2 || expr2 logical OR
21802208
*
21812209
* "arg" must point to the first non-white of the expression.
2182-
* "arg" is advanced to the next non-white after the recognized expression.
2210+
* "arg" is advanced to just after the recognized expression.
21832211
*
21842212
* Return OK or FAIL.
21852213
*/
@@ -2310,7 +2338,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
23102338
* expr3 && expr3 && expr3 logical AND
23112339
*
23122340
* "arg" must point to the first non-white of the expression.
2313-
* "arg" is advanced to the next non-white after the recognized expression.
2341+
* "arg" is advanced to just after the recognized expression.
23142342
*
23152343
* Return OK or FAIL.
23162344
*/

src/testdir/test_vim9_expr.vim

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def Test_expr1()
6060
enddef
6161

6262
def Test_expr1_vimscript()
63-
# only checks line continuation
63+
# check line continuation
6464
let lines =<< trim END
6565
vim9script
6666
let var = 1
@@ -87,6 +87,33 @@ def Test_expr1_vimscript()
8787
assert_equal('no', var)
8888
END
8989
CheckScriptSuccess(lines)
90+
91+
# check white space
92+
lines =<< trim END
93+
vim9script
94+
let var = v:true?1:2
95+
END
96+
CheckScriptFailure(lines, 'E1004:')
97+
lines =<< trim END
98+
vim9script
99+
let var = v:true? 1 : 2
100+
END
101+
CheckScriptFailure(lines, 'E1004:')
102+
lines =<< trim END
103+
vim9script
104+
let var = v:true ?1 : 2
105+
END
106+
CheckScriptFailure(lines, 'E1004:')
107+
lines =<< trim END
108+
vim9script
109+
let var = v:true ? 1: 2
110+
END
111+
CheckScriptFailure(lines, 'E1004:')
112+
lines =<< trim END
113+
vim9script
114+
let var = v:true ? 1 :2
115+
END
116+
CheckScriptFailure(lines, 'E1004:')
90117
enddef
91118

92119
func Test_expr1_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+
1372,
757759
/**/
758760
1371,
759761
/**/

0 commit comments

Comments
 (0)