0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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.
This commit is contained in:
Bram Moolenaar
2020-03-01 14:04:46 +01:00
parent f4f190d821
commit fbdd08ed9b
7 changed files with 609 additions and 500 deletions

View File

@@ -752,6 +752,12 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
get_buffer_lines(buf, lnum, end, TRUE, rettv);
}
type_T *
ret_f_getline(int argcount, type_T **argtypes UNUSED)
{
return argcount == 1 ? &t_string : &t_list_string;
}
/*
* "getline(lnum, [end])" function
*/

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@ void f_bufwinnr(typval_T *argvars, typval_T *rettv);
void f_deletebufline(typval_T *argvars, typval_T *rettv);
void f_getbufinfo(typval_T *argvars, typval_T *rettv);
void f_getbufline(typval_T *argvars, typval_T *rettv);
type_T *ret_f_getline(int argcount, type_T **argtypes);
void f_getline(typval_T *argvars, typval_T *rettv);
void f_setbufline(typval_T *argvars, typval_T *rettv);
void f_setline(typval_T *argvars, typval_T *rettv);

View File

@@ -4,7 +4,7 @@ char_u *get_expr_name(expand_T *xp, int idx);
int find_internal_func(char_u *name);
int has_internal_func(char_u *name);
char *internal_func_name(int idx);
type_T *internal_func_ret_type(int idx, int argcount);
type_T *internal_func_ret_type(int idx, int argcount, type_T **argtypes);
int check_internal_func(int idx, int argcount);
int call_internal_func(char_u *name, int argcount, typval_T *argvars, typval_T *rettv);
void call_internal_func_by_idx(int idx, typval_T *argvars, typval_T *rettv);

View File

@@ -55,7 +55,12 @@ def Test_assignment()
if has('channel')
let chan1: channel
let job1: job
endif
if has('float')
let float1: float = 3.4
endif
let party: partial = funcref('Test_syntax')
g:newvar = 'new'
assert_equal('new', g:newvar)

View File

@@ -738,6 +738,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
339,
/**/
338,
/**/

View File

@@ -992,6 +992,8 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount)
{
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 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount)
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 @@ parse_type(char_u **arg, garray_T *type_list)
}
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