mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Problem: Vim9: "++var" and "--var" are silently accepted. Solution: Give an error message.
This commit is contained in:
26
src/eval.c
26
src/eval.c
@@ -3188,6 +3188,28 @@ eval6(
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
eval_leader(char_u **arg, int vim9)
|
||||||
|
{
|
||||||
|
char_u *s = *arg;
|
||||||
|
char_u *p = *arg;
|
||||||
|
|
||||||
|
while (*p == '!' || *p == '-' || *p == '+')
|
||||||
|
{
|
||||||
|
char_u *n = skipwhite(p + 1);
|
||||||
|
|
||||||
|
// ++, --, -+ and +- are not accepted in Vim9 script
|
||||||
|
if (vim9 && (*p == '-' || *p == '+') && (*n == '-' || *n == '+'))
|
||||||
|
{
|
||||||
|
semsg(_(e_invexpr2), s);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
p = n;
|
||||||
|
}
|
||||||
|
*arg = p;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle sixth level expression:
|
* Handle sixth level expression:
|
||||||
* number number constant
|
* number number constant
|
||||||
@@ -3243,8 +3265,8 @@ eval7(
|
|||||||
* Skip '!', '-' and '+' characters. They are handled later.
|
* Skip '!', '-' and '+' characters. They are handled later.
|
||||||
*/
|
*/
|
||||||
start_leader = *arg;
|
start_leader = *arg;
|
||||||
while (**arg == '!' || **arg == '-' || **arg == '+')
|
if (eval_leader(arg, in_vim9script()) == FAIL)
|
||||||
*arg = skipwhite(*arg + 1);
|
return FAIL;
|
||||||
end_leader = *arg;
|
end_leader = *arg;
|
||||||
|
|
||||||
if (**arg == '.' && (!isdigit(*(*arg + 1))
|
if (**arg == '.' && (!isdigit(*(*arg + 1))
|
||||||
|
@@ -39,6 +39,7 @@ int eval0(char_u *arg, typval_T *rettv, exarg_T *eap, evalarg_T *evalarg);
|
|||||||
int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
|
int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
|
||||||
void eval_addblob(typval_T *tv1, typval_T *tv2);
|
void eval_addblob(typval_T *tv1, typval_T *tv2);
|
||||||
int eval_addlist(typval_T *tv1, typval_T *tv2);
|
int eval_addlist(typval_T *tv1, typval_T *tv2);
|
||||||
|
int eval_leader(char_u **arg, int vim9);
|
||||||
int check_can_index(typval_T *rettv, int evaluate, int verbose);
|
int check_can_index(typval_T *rettv, int evaluate, int verbose);
|
||||||
int eval_index_inner(typval_T *rettv, int is_range, typval_T *var1, typval_T *var2, char_u *key, int keylen, int verbose);
|
int eval_index_inner(typval_T *rettv, int is_range, typval_T *var1, typval_T *var2, char_u *key, int keylen, int verbose);
|
||||||
char_u *partial_name(partial_T *pt);
|
char_u *partial_name(partial_T *pt);
|
||||||
|
@@ -2516,11 +2516,8 @@ def Test_expr7_parens()
|
|||||||
|
|
||||||
assert_equal(6, +6)
|
assert_equal(6, +6)
|
||||||
assert_equal(-6, -6)
|
assert_equal(-6, -6)
|
||||||
assert_equal(6, --6)
|
|
||||||
assert_equal(6, -+-6)
|
|
||||||
assert_equal(-6, ---6)
|
|
||||||
assert_equal(false, !-3)
|
assert_equal(false, !-3)
|
||||||
assert_equal(true, !+-+0)
|
assert_equal(true, !+0)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr7_parens_vim9script()
|
def Test_expr7_parens_vim9script()
|
||||||
@@ -2539,26 +2536,56 @@ enddef
|
|||||||
def Test_expr7_negate_add()
|
def Test_expr7_negate_add()
|
||||||
assert_equal(-99, -99)
|
assert_equal(-99, -99)
|
||||||
assert_equal(-99, - 99)
|
assert_equal(-99, - 99)
|
||||||
assert_equal(99, --99)
|
|
||||||
assert_equal(99, -- 99)
|
|
||||||
assert_equal(99, - - 99)
|
|
||||||
assert_equal(99, +99)
|
assert_equal(99, +99)
|
||||||
assert_equal(-99, -+99)
|
|
||||||
assert_equal(-99, -+ 99)
|
|
||||||
assert_equal(-99, - +99)
|
|
||||||
assert_equal(-99, - + 99)
|
|
||||||
assert_equal(-99, +-99)
|
|
||||||
assert_equal(-99, + -99)
|
|
||||||
assert_equal(-99, + - 99)
|
|
||||||
|
|
||||||
var nr = 88
|
var nr = 88
|
||||||
assert_equal(-88, -nr)
|
assert_equal(-88, -nr)
|
||||||
assert_equal(-88, - nr)
|
assert_equal(-88, - nr)
|
||||||
assert_equal(-88, - +nr)
|
|
||||||
assert_equal(88, -- nr)
|
|
||||||
assert_equal(88, + nr)
|
assert_equal(88, + nr)
|
||||||
assert_equal(88, --+ nr)
|
|
||||||
assert_equal(88, - - nr)
|
var lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo ++n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo --n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo +-n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo -+n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo - -n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
echo + +n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E15:')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
:1
|
||||||
|
++n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E1050:')
|
||||||
|
lines =<< trim END
|
||||||
|
var n = 12
|
||||||
|
:1
|
||||||
|
--n
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E1050:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Echo(arg: any): string
|
def Echo(arg: any): string
|
||||||
@@ -2573,7 +2600,7 @@ def Test_expr7_call()
|
|||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
assert_equal('yes', 'yes'->Echo())
|
assert_equal('yes', 'yes'->Echo())
|
||||||
assert_equal(true, !range(5)->empty())
|
assert_equal(true, !range(5)->empty())
|
||||||
assert_equal([0, 1, 2], --3->range())
|
assert_equal([0, 1, 2], 3->range())
|
||||||
END
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
|
@@ -750,6 +750,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 */
|
||||||
|
/**/
|
||||||
|
2305,
|
||||||
/**/
|
/**/
|
||||||
2304,
|
2304,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -3887,8 +3887,8 @@ compile_expr7(
|
|||||||
* Skip '!', '-' and '+' characters. They are handled later.
|
* Skip '!', '-' and '+' characters. They are handled later.
|
||||||
*/
|
*/
|
||||||
start_leader = *arg;
|
start_leader = *arg;
|
||||||
while (**arg == '!' || **arg == '-' || **arg == '+')
|
if (eval_leader(arg, TRUE) == FAIL)
|
||||||
*arg = skipwhite(*arg + 1);
|
return FAIL;
|
||||||
end_leader = *arg;
|
end_leader = *arg;
|
||||||
|
|
||||||
rettv->v_type = VAR_UNKNOWN;
|
rettv->v_type = VAR_UNKNOWN;
|
||||||
|
Reference in New Issue
Block a user