diff src/evalfunc.c @ 21089:d69ead03ba93 v8.2.1096

patch 8.2.1096: Vim9: return type of getqflist() is wrong Commit: https://github.com/vim/vim/commit/f151ad1c70825a91afb112e611db5c712e2656ef Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 30 13:38:01 2020 +0200 patch 8.2.1096: Vim9: return type of getqflist() is wrong Problem: Vim9: return type of getqflist() is wrong. Solution: Let the return type depend on the arguments. Also for getloclist(). (closes #6367)
author Bram Moolenaar <Bram@vim.org>
date Tue, 30 Jun 2020 13:45:06 +0200
parents c2a368193769
children 4d844a65183d
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -347,6 +347,30 @@ ret_first_arg(int argcount, type_T **arg
     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},