summaryrefslogtreecommitdiff
path: root/src/vim9execute.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/vim9execute.c
parent7193323b7796c05573f3aa89d422e848feb3a8dc (diff)
downloadvim-git-47bba53bdb6d59057887149e2eeb2071803e547e.tar.gz
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/vim9execute.c')
-rw-r--r--src/vim9execute.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c
index d0dbefc43..57f875de3 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -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;
}