mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.3353: Vim9: type of argument for negate not checked at compile time
Problem: Vim9: type of argument for negate not checked at compile time. Solution: Add a compile time check.
This commit is contained in:
@@ -1680,25 +1680,27 @@ def Test_disassemble_any_slice()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def NegateNumber(): number
|
def NegateNumber(): number
|
||||||
var nr = 9
|
g:nr = 9
|
||||||
var plus = +nr
|
var plus = +g:nr
|
||||||
var res = -nr
|
var minus = -g:nr
|
||||||
return res
|
return minus
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_disassemble_negate_number()
|
def Test_disassemble_negate_number()
|
||||||
var instr = execute('disassemble NegateNumber')
|
var instr = execute('disassemble NegateNumber')
|
||||||
assert_match('NegateNumber\_s*' ..
|
assert_match('NegateNumber\_s*' ..
|
||||||
'var nr = 9\_s*' ..
|
'g:nr = 9\_s*' ..
|
||||||
'\d STORE 9 in $0\_s*' ..
|
'\d PUSHNR 9\_s*' ..
|
||||||
'var plus = +nr\_s*' ..
|
'\d STOREG g:nr\_s*' ..
|
||||||
'\d LOAD $0\_s*' ..
|
'var plus = +g:nr\_s*' ..
|
||||||
'\d CHECKNR\_s*' ..
|
'\d LOADG g:nr\_s*' ..
|
||||||
'\d STORE $1\_s*' ..
|
'\d CHECKTYPE number stack\[-1\]\_s*' ..
|
||||||
'var res = -nr\_s*' ..
|
'\d STORE $0\_s*' ..
|
||||||
'\d LOAD $0\_s*' ..
|
'var minus = -g:nr\_s*' ..
|
||||||
|
'\d LOADG g:nr\_s*' ..
|
||||||
|
'\d CHECKTYPE number stack\[-1\]\_s*' ..
|
||||||
'\d NEGATENR\_s*' ..
|
'\d NEGATENR\_s*' ..
|
||||||
'\d STORE $2\_s*',
|
'\d STORE $1\_s*',
|
||||||
instr)
|
instr)
|
||||||
assert_equal(-9, NegateNumber())
|
assert_equal(-9, NegateNumber())
|
||||||
enddef
|
enddef
|
||||||
|
@@ -3123,6 +3123,17 @@ def Test_expr7_not()
|
|||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
let g:anumber = 42
|
||||||
|
|
||||||
|
def Test_expr7_negate()
|
||||||
|
var lines =<< trim END
|
||||||
|
var nr = 1
|
||||||
|
assert_equal(-1, -nr)
|
||||||
|
assert_equal(-42, -g:anumber)
|
||||||
|
END
|
||||||
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
func Test_expr7_fails()
|
func Test_expr7_fails()
|
||||||
call CheckDefFailure(["var x = (12"], "E1097:", 3)
|
call CheckDefFailure(["var x = (12"], "E1097:", 3)
|
||||||
call CheckScriptFailure(['vim9script', "var x = (12"], 'E110:', 2)
|
call CheckScriptFailure(['vim9script', "var x = (12"], 'E110:', 2)
|
||||||
@@ -3130,8 +3141,8 @@ func Test_expr7_fails()
|
|||||||
call CheckDefAndScriptFailure(["var x = -'xx'"], "E1030:", 1)
|
call CheckDefAndScriptFailure(["var x = -'xx'"], "E1030:", 1)
|
||||||
call CheckDefAndScriptFailure(["var x = +'xx'"], "E1030:", 1)
|
call CheckDefAndScriptFailure(["var x = +'xx'"], "E1030:", 1)
|
||||||
call CheckDefAndScriptFailure(["var x = -0z12"], "E974:", 1)
|
call CheckDefAndScriptFailure(["var x = -0z12"], "E974:", 1)
|
||||||
call CheckDefExecAndScriptFailure2(["var x = -[8]"], "E39:", 'E745:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = -[8]"], "E1012:", 'E745:', 1)
|
||||||
call CheckDefExecAndScriptFailure2(["var x = -{a: 1}"], "E39:", 'E728:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = -{a: 1}"], "E1012:", 'E728:', 1)
|
||||||
|
|
||||||
call CheckDefAndScriptFailure(["var x = @"], "E1002:", 1)
|
call CheckDefAndScriptFailure(["var x = @"], "E1002:", 1)
|
||||||
call CheckDefAndScriptFailure(["var x = @<"], "E354:", 1)
|
call CheckDefAndScriptFailure(["var x = @<"], "E354:", 1)
|
||||||
@@ -3154,10 +3165,10 @@ func Test_expr7_fails()
|
|||||||
call CheckDefAndScriptFailure2(["echo l:somevar"], 'E1075:', 'E121:', 1)
|
call CheckDefAndScriptFailure2(["echo l:somevar"], 'E1075:', 'E121:', 1)
|
||||||
call CheckDefAndScriptFailure2(["echo x:somevar"], 'E1075:', 'E121:', 1)
|
call CheckDefAndScriptFailure2(["echo x:somevar"], 'E1075:', 'E121:', 1)
|
||||||
|
|
||||||
call CheckDefExecAndScriptFailure(["var x = +g:astring"], 'E1030:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = +g:astring"], 'E1012:', 'E1030:', 1)
|
||||||
call CheckDefExecAndScriptFailure(["var x = +g:ablob"], 'E974:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = +g:ablob"], 'E1012:', 'E974:', 1)
|
||||||
call CheckDefExecAndScriptFailure(["var x = +g:alist"], 'E745:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = +g:alist"], 'E1012:', 'E745:', 1)
|
||||||
call CheckDefExecAndScriptFailure(["var x = +g:adict"], 'E728:', 1)
|
call CheckDefExecAndScriptFailure2(["var x = +g:adict"], 'E1012:', 'E728:', 1)
|
||||||
|
|
||||||
call CheckDefAndScriptFailure2(["var x = ''", "var y = x.memb"], 'E1229: Expected dictionary for using key "memb", but got string', 'E488:', 2)
|
call CheckDefAndScriptFailure2(["var x = ''", "var y = x.memb"], 'E1229: Expected dictionary for using key "memb", but got string', 'E488:', 2)
|
||||||
|
|
||||||
|
@@ -469,21 +469,21 @@ def Test_try_catch_throw()
|
|||||||
|
|
||||||
try
|
try
|
||||||
n = -g:astring
|
n = -g:astring
|
||||||
catch /E39:/
|
catch /E1012:/
|
||||||
n = 233
|
n = 233
|
||||||
endtry
|
endtry
|
||||||
assert_equal(233, n)
|
assert_equal(233, n)
|
||||||
|
|
||||||
try
|
try
|
||||||
n = +g:astring
|
n = +g:astring
|
||||||
catch /E1030:/
|
catch /E1012:/
|
||||||
n = 244
|
n = 244
|
||||||
endtry
|
endtry
|
||||||
assert_equal(244, n)
|
assert_equal(244, n)
|
||||||
|
|
||||||
try
|
try
|
||||||
n = +g:alist
|
n = +g:alist
|
||||||
catch /E745:/
|
catch /E1012:/
|
||||||
n = 255
|
n = 255
|
||||||
endtry
|
endtry
|
||||||
assert_equal(255, n)
|
assert_equal(255, n)
|
||||||
|
@@ -755,6 +755,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 */
|
||||||
|
/**/
|
||||||
|
3353,
|
||||||
/**/
|
/**/
|
||||||
3352,
|
3352,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -4210,10 +4210,15 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
|
|||||||
--p;
|
--p;
|
||||||
if (*p == '-' || *p == '+')
|
if (*p == '-' || *p == '+')
|
||||||
{
|
{
|
||||||
int negate = *p == '-';
|
int negate = *p == '-';
|
||||||
isn_T *isn;
|
isn_T *isn;
|
||||||
|
garray_T *stack = &cctx->ctx_type_stack;
|
||||||
|
type_T *type;
|
||||||
|
|
||||||
|
type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
|
if (need_type(type, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
// TODO: check type
|
|
||||||
while (p > start && (p[-1] == '-' || p[-1] == '+'))
|
while (p > start && (p[-1] == '-' || p[-1] == '+'))
|
||||||
{
|
{
|
||||||
--p;
|
--p;
|
||||||
@@ -4222,11 +4227,11 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
|
|||||||
}
|
}
|
||||||
// only '-' has an effect, for '+' we only check the type
|
// only '-' has an effect, for '+' we only check the type
|
||||||
if (negate)
|
if (negate)
|
||||||
|
{
|
||||||
isn = generate_instr(cctx, ISN_NEGATENR);
|
isn = generate_instr(cctx, ISN_NEGATENR);
|
||||||
else
|
if (isn == NULL)
|
||||||
isn = generate_instr(cctx, ISN_CHECKNR);
|
return FAIL;
|
||||||
if (isn == NULL)
|
}
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
else if (numeric_only)
|
else if (numeric_only)
|
||||||
{
|
{
|
||||||
@@ -5809,7 +5814,6 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
|
r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
|
||||||
}
|
}
|
||||||
// TODO: warning for trailing text?
|
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
vim_free(lambda_name);
|
vim_free(lambda_name);
|
||||||
@@ -5852,7 +5856,6 @@ generate_loadvar(
|
|||||||
switch (dest)
|
switch (dest)
|
||||||
{
|
{
|
||||||
case dest_option:
|
case dest_option:
|
||||||
// TODO: check the option exists
|
|
||||||
generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
|
generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
|
||||||
break;
|
break;
|
||||||
case dest_global:
|
case dest_global:
|
||||||
|
Reference in New Issue
Block a user