0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 8.2.1858: Vim9: filter functions return number instead of bool

Problem:    Vim9: filter functions return number instead of bool.
Solution:   Return v:true instead of one. (closes #7144)
This commit is contained in:
Bram Moolenaar
2020-10-17 19:29:51 +02:00
parent 218450ad5e
commit 403dc31f5a
4 changed files with 27 additions and 4 deletions

View File

@@ -270,6 +270,11 @@ ret_any(int argcount UNUSED, type_T **argtypes UNUSED)
return &t_any;
}
static type_T *
ret_bool(int argcount UNUSED, type_T **argtypes UNUSED)
{
return &t_bool;
}
static type_T *
ret_number(int argcount UNUSED, type_T **argtypes UNUSED)
{
return &t_number;
@@ -793,8 +798,8 @@ static funcentry_T global_functions[] =
{"popup_close", 1, 2, FEARG_1, ret_void, PROP_FUNC(f_popup_close)},
{"popup_create", 2, 2, FEARG_1, ret_number, PROP_FUNC(f_popup_create)},
{"popup_dialog", 2, 2, FEARG_1, ret_number, PROP_FUNC(f_popup_dialog)},
{"popup_filter_menu", 2, 2, 0, ret_number, PROP_FUNC(f_popup_filter_menu)},
{"popup_filter_yesno", 2, 2, 0, ret_number, PROP_FUNC(f_popup_filter_yesno)},
{"popup_filter_menu", 2, 2, 0, ret_bool, PROP_FUNC(f_popup_filter_menu)},
{"popup_filter_yesno", 2, 2, 0, ret_bool, PROP_FUNC(f_popup_filter_yesno)},
{"popup_findinfo", 0, 0, 0, ret_number, PROP_FUNC(f_popup_findinfo)},
{"popup_findpreview", 0, 0, 0, ret_number, PROP_FUNC(f_popup_findpreview)},
{"popup_getoptions", 1, 1, FEARG_1, ret_dict_any, PROP_FUNC(f_popup_getoptions)},

View File

@@ -2375,7 +2375,8 @@ f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
c = TO_SPECIAL(key[1], key[2]);
// consume all keys until done
rettv->vval.v_number = 1;
rettv->v_type = VAR_BOOL;
rettv->vval.v_number = VVAL_TRUE;
res.v_type = VAR_NUMBER;
old_lnum = wp->w_cursor.lnum;
@@ -2429,7 +2430,8 @@ f_popup_filter_yesno(typval_T *argvars, typval_T *rettv)
c = TO_SPECIAL(key[1], key[2]);
// consume all keys until done
rettv->vval.v_number = 1;
rettv->v_type = VAR_BOOL;
rettv->vval.v_number = VVAL_TRUE;
if (c == 'y' || c == 'Y')
res.vval.v_number = 1;

View File

@@ -94,6 +94,20 @@ def Test_missing_return()
'enddef'], 'E1095:')
enddef
def Test_return_bool()
var lines =<< trim END
vim9script
def MenuFilter(id: number, key: string): bool
return popup_filter_menu(id, key)
enddef
def YesnoFilter(id: number, key: string): bool
return popup_filter_yesno(id, key)
enddef
defcompile
END
CheckScriptSuccess(lines)
enddef
let s:nothing = 0
def ReturnNothing()
s:nothing = 1

View File

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