summaryrefslogtreecommitdiffstats
path: root/src/vim9type.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-20 18:49:46 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-20 18:49:46 +0000
commit47bba53bdb6d59057887149e2eeb2071803e547e (patch)
tree03409a5588fe07989acce53eeaf8d591229c4e9d /src/vim9type.c
parent7193323b7796c05573f3aa89d422e848feb3a8dc (diff)
patch 9.0.1224: cannot call a :def function with a number for float argumentv9.0.1224
Problem: Cannot call a :def function with a number for a float argument. Solution: Accept a number as well, convert it to a float.
Diffstat (limited to 'src/vim9type.c')
-rw-r--r--src/vim9type.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/vim9type.c b/src/vim9type.c
index 08dabd1c22..61853956e8 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -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);