1
0
forked from aniani/vim

patch 9.0.1224: cannot call a :def function with a number for float argument

Problem:    Cannot call a :def function with a number for a float argument.
Solution:   Accept a number as well, convert it to a float.
This commit is contained in:
Bram Moolenaar
2023-01-20 18:49:46 +00:00
parent 7193323b77
commit 47bba53bdb
6 changed files with 158 additions and 116 deletions

View File

@@ -5822,12 +5822,25 @@ call_def_function(
}
else
{
if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len
&& check_typval_arg_type(
ufunc->uf_arg_types[idx], tv,
int done = FALSE;
if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len)
{
type_T *expected = ufunc->uf_arg_types[idx];
if (expected->tt_type == VAR_FLOAT && tv->v_type == VAR_NUMBER)
{
// When a float is expected and a number was given, convert
// the value.
STACK_TV_BOT(0)->v_type = VAR_FLOAT;
STACK_TV_BOT(0)->v_lock = 0;
STACK_TV_BOT(0)->vval.v_float = tv->vval.v_number;
done = TRUE;
}
else if (check_typval_arg_type(expected, tv,
NULL, argv_idx + 1) == FAIL)
goto failed_early;
copy_tv(tv, STACK_TV_BOT(0));
goto failed_early;
}
if (!done)
copy_tv(tv, STACK_TV_BOT(0));
}
++ectx.ec_stack.ga_len;
}