patch 8.2.0339: Vim9: function return type may depend on arguments
Problem: Vim9: function return type may depend on arguments.
Solution: Instead of a fixed return type use a function to figure out the
return type.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 2e0c2ff..4fb5478 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -992,6 +992,8 @@
{
isn_T *isn;
garray_T *stack = &cctx->ctx_type_stack;
+ type_T *argtypes[MAX_FUNC_ARGS];
+ int i;
if (check_internal_func(func_idx, argcount) == FAIL)
return FAIL;
@@ -1001,11 +1003,14 @@
isn->isn_arg.bfunc.cbf_idx = func_idx;
isn->isn_arg.bfunc.cbf_argcount = argcount;
+ for (i = 0; i < argcount; ++i)
+ argtypes[i] = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
+
stack->ga_len -= argcount; // drop the arguments
if (ga_grow(stack, 1) == FAIL)
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] =
- internal_func_ret_type(func_idx, argcount);
+ internal_func_ret_type(func_idx, argcount, argtypes);
++stack->ga_len; // add return value
return OK;
@@ -1374,7 +1379,7 @@
}
break;
case 'p':
- if (len == 4 && STRNCMP(*arg, "partial", len) == 0)
+ if (len == 7 && STRNCMP(*arg, "partial", len) == 0)
{
*arg += len;
// TODO: arguments and return type