mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.3161: Vim9: no error when reltime() has invalid arguments
Problem: Vim9: no error when reltime() has invalid arguments. Solution: Add an error. (closes #8562)
This commit is contained in:
@@ -1652,6 +1652,11 @@ def Test_readfile()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_reltime()
|
def Test_reltime()
|
||||||
|
CheckFeature reltime
|
||||||
|
|
||||||
|
CheckDefExecAndScriptFailure(['[]->reltime()'], 'E474:')
|
||||||
|
CheckDefExecAndScriptFailure(['[]->reltime([])'], 'E474:')
|
||||||
|
|
||||||
CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
|
CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
|
||||||
CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
|
CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
|
||||||
CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
|
CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
|
||||||
@@ -1663,12 +1668,20 @@ def Test_reltime()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_reltimefloat()
|
def Test_reltimefloat()
|
||||||
|
CheckFeature reltime
|
||||||
|
|
||||||
|
CheckDefExecAndScriptFailure(['[]->reltimefloat()'], 'E474:')
|
||||||
|
|
||||||
CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
|
CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
|
||||||
CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
|
CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
|
||||||
assert_true(type(reltimefloat(reltime())) == v:t_float)
|
assert_true(type(reltimefloat(reltime())) == v:t_float)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_reltimestr()
|
def Test_reltimestr()
|
||||||
|
CheckFeature reltime
|
||||||
|
|
||||||
|
CheckDefExecAndScriptFailure(['[]->reltimestr()'], 'E474:')
|
||||||
|
|
||||||
CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
|
CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
|
||||||
CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
|
CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
|
||||||
assert_true(type(reltimestr(reltime())) == v:t_string)
|
assert_true(type(reltimestr(reltime())) == v:t_string)
|
||||||
|
12
src/time.c
12
src/time.c
@@ -178,7 +178,11 @@ f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
|||||||
else if (argvars[1].v_type == VAR_UNKNOWN)
|
else if (argvars[1].v_type == VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
if (list2proftime(&argvars[0], &res) == FAIL)
|
if (list2proftime(&argvars[0], &res) == FAIL)
|
||||||
|
{
|
||||||
|
if (in_vim9script())
|
||||||
|
emsg(_(e_invarg));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
profile_end(&res);
|
profile_end(&res);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -186,7 +190,11 @@ f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
|||||||
// Two arguments: compute the difference.
|
// Two arguments: compute the difference.
|
||||||
if (list2proftime(&argvars[0], &start) == FAIL
|
if (list2proftime(&argvars[0], &start) == FAIL
|
||||||
|| list2proftime(&argvars[1], &res) == FAIL)
|
|| list2proftime(&argvars[1], &res) == FAIL)
|
||||||
|
{
|
||||||
|
if (in_vim9script())
|
||||||
|
emsg(_(e_invarg));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
profile_sub(&res, &start);
|
profile_sub(&res, &start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +231,8 @@ f_reltimefloat(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
# ifdef FEAT_RELTIME
|
# ifdef FEAT_RELTIME
|
||||||
if (list2proftime(&argvars[0], &tm) == OK)
|
if (list2proftime(&argvars[0], &tm) == OK)
|
||||||
rettv->vval.v_float = profile_float(&tm);
|
rettv->vval.v_float = profile_float(&tm);
|
||||||
|
else if (in_vim9script())
|
||||||
|
emsg(_(e_invarg));
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
@@ -242,6 +252,8 @@ f_reltimestr(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
# ifdef FEAT_RELTIME
|
# ifdef FEAT_RELTIME
|
||||||
if (list2proftime(&argvars[0], &tm) == OK)
|
if (list2proftime(&argvars[0], &tm) == OK)
|
||||||
rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm));
|
rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm));
|
||||||
|
else if (in_vim9script())
|
||||||
|
emsg(_(e_invarg));
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
3161,
|
||||||
/**/
|
/**/
|
||||||
3160,
|
3160,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user