summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-30 13:38:01 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-30 13:38:01 +0200
commitf151ad1c70825a91afb112e611db5c712e2656ef (patch)
treea6bd0649f863bc25b72cb815133db956982035bc
parent6b949615edac2dd33d5e865be8328561f296b045 (diff)
patch 8.2.1096: Vim9: return type of getqflist() is wrongv8.2.1096
Problem: Vim9: return type of getqflist() is wrong. Solution: Let the return type depend on the arguments. Also for getloclist(). (closes #6367)
-rw-r--r--src/evalfunc.c28
-rw-r--r--src/testdir/test_vim9_func.vim16
-rw-r--r--src/version.c2
3 files changed, 44 insertions, 2 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 6ca450306d..b8f1c2c38e 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -347,6 +347,30 @@ ret_first_arg(int argcount, type_T **argtypes)
return &t_void;
}
+/*
+ * Used for getqflist(): returns list if there is no argument, dict if there is
+ * one.
+ */
+ static type_T *
+ret_list_or_dict_0(int argcount, type_T **argtypes UNUSED)
+{
+ if (argcount > 0)
+ return &t_dict_any;
+ return &t_list_dict_any;
+}
+
+/*
+ * Used for getloclist(): returns list if there is one argument, dict if there
+ * are two.
+ */
+ static type_T *
+ret_list_or_dict_1(int argcount, type_T **argtypes UNUSED)
+{
+ if (argcount > 1)
+ return &t_dict_any;
+ return &t_list_dict_any;
+}
+
static type_T *ret_f_function(int argcount, type_T **argtypes);
/*
@@ -588,13 +612,13 @@ static funcentry_T global_functions[] =
{"getimstatus", 0, 0, 0, ret_number, f_getimstatus},
{"getjumplist", 0, 2, FEARG_1, ret_list_any, f_getjumplist},
{"getline", 1, 2, FEARG_1, ret_f_getline, f_getline},
- {"getloclist", 1, 2, 0, ret_list_dict_any, f_getloclist},
+ {"getloclist", 1, 2, 0, ret_list_or_dict_1, f_getloclist},
{"getmarklist", 0, 1, FEARG_1, ret_list_dict_any, f_getmarklist},
{"getmatches", 0, 1, 0, ret_list_dict_any, f_getmatches},
{"getmousepos", 0, 0, 0, ret_dict_number, f_getmousepos},
{"getpid", 0, 0, 0, ret_number, f_getpid},
{"getpos", 1, 1, FEARG_1, ret_list_number, f_getpos},
- {"getqflist", 0, 1, 0, ret_list_dict_any, f_getqflist},
+ {"getqflist", 0, 1, 0, ret_list_or_dict_0, f_getqflist},
{"getreg", 0, 3, FEARG_1, ret_string, f_getreg},
{"getreginfo", 0, 1, FEARG_1, ret_dict_any, f_getreginfo},
{"getregtype", 0, 1, FEARG_1, ret_string, f_getregtype},
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index fbe73f7dcf..1fc13c088d 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -837,6 +837,22 @@ def Test_sort_return_type()
res = [1, 2, 3]->sort()
enddef
+def Test_getqflist_return_type()
+ let l = getqflist()
+ assert_equal([], l)
+
+ let d = getqflist(#{items: 0})
+ assert_equal(#{items: []}, d)
+enddef
+
+def Test_getloclist_return_type()
+ let l = getloclist(1)
+ assert_equal([], l)
+
+ let d = getloclist(1, #{items: 0})
+ assert_equal(#{items: []}, d)
+enddef
+
def Line_continuation_in_def(dir: string = ''): string
let path: string = empty(dir)
\ ? 'empty'
diff --git a/src/version.c b/src/version.c
index 4406488bbd..f0ed380301 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1096,
+/**/
1095,
/**/
1094,