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

@@ -628,12 +628,17 @@ typval2type(typval_T *tv, int copyID, garray_T *type_gap, int flags)
{
type_T *type = typval2type_int(tv, copyID, type_gap, flags);
if (type != NULL && type != &t_bool
&& (tv->v_type == VAR_NUMBER
if (type != NULL)
{
if (type != &t_bool && (tv->v_type == VAR_NUMBER
&& (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
// Number 0 and 1 and expression with "&&" or "||" can also be used for
// bool.
type = &t_number_bool;
// Number 0 and 1 and expression with "&&" or "||" can also be used
// for bool.
type = &t_number_bool;
else if (type != &t_float && tv->v_type == VAR_NUMBER)
// A number can also be used for float.
type = &t_number_float;
}
return type;
}
@@ -821,9 +826,10 @@ check_type_maybe(
// Using number 0 or 1 for bool is OK.
return OK;
if (expected->tt_type == VAR_FLOAT
&& (expected->tt_flags & TTFLAG_NUMBER_OK)
&& actual->tt_type == VAR_NUMBER)
// Using number where float is expected is OK here.
&& actual->tt_type == VAR_NUMBER
&& ((expected->tt_flags & TTFLAG_NUMBER_OK)
|| (actual->tt_flags & TTFLAG_FLOAT_OK)))
// Using a number where a float is expected is OK here.
return OK;
if (give_msg)
type_mismatch_where(expected, actual, where);