• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisiond69ead03ba93bf055de188d69b3ae91ea311d3ba (tree)
Time2020-06-30 20:45:06
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

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)

Change Summary

Incremental Difference

diff -r 949a9ea0cfce -r d69ead03ba93 src/evalfunc.c
--- a/src/evalfunc.c Mon Jun 29 23:30:05 2020 +0200
+++ b/src/evalfunc.c Tue Jun 30 13:45:06 2020 +0200
@@ -347,6 +347,30 @@
347347 return &t_void;
348348 }
349349
350+/*
351+ * Used for getqflist(): returns list if there is no argument, dict if there is
352+ * one.
353+ */
354+ static type_T *
355+ret_list_or_dict_0(int argcount, type_T **argtypes UNUSED)
356+{
357+ if (argcount > 0)
358+ return &t_dict_any;
359+ return &t_list_dict_any;
360+}
361+
362+/*
363+ * Used for getloclist(): returns list if there is one argument, dict if there
364+ * are two.
365+ */
366+ static type_T *
367+ret_list_or_dict_1(int argcount, type_T **argtypes UNUSED)
368+{
369+ if (argcount > 1)
370+ return &t_dict_any;
371+ return &t_list_dict_any;
372+}
373+
350374 static type_T *ret_f_function(int argcount, type_T **argtypes);
351375
352376 /*
@@ -588,13 +612,13 @@
588612 {"getimstatus", 0, 0, 0, ret_number, f_getimstatus},
589613 {"getjumplist", 0, 2, FEARG_1, ret_list_any, f_getjumplist},
590614 {"getline", 1, 2, FEARG_1, ret_f_getline, f_getline},
591- {"getloclist", 1, 2, 0, ret_list_dict_any, f_getloclist},
615+ {"getloclist", 1, 2, 0, ret_list_or_dict_1, f_getloclist},
592616 {"getmarklist", 0, 1, FEARG_1, ret_list_dict_any, f_getmarklist},
593617 {"getmatches", 0, 1, 0, ret_list_dict_any, f_getmatches},
594618 {"getmousepos", 0, 0, 0, ret_dict_number, f_getmousepos},
595619 {"getpid", 0, 0, 0, ret_number, f_getpid},
596620 {"getpos", 1, 1, FEARG_1, ret_list_number, f_getpos},
597- {"getqflist", 0, 1, 0, ret_list_dict_any, f_getqflist},
621+ {"getqflist", 0, 1, 0, ret_list_or_dict_0, f_getqflist},
598622 {"getreg", 0, 3, FEARG_1, ret_string, f_getreg},
599623 {"getreginfo", 0, 1, FEARG_1, ret_dict_any, f_getreginfo},
600624 {"getregtype", 0, 1, FEARG_1, ret_string, f_getregtype},
diff -r 949a9ea0cfce -r d69ead03ba93 src/testdir/test_vim9_func.vim
--- a/src/testdir/test_vim9_func.vim Mon Jun 29 23:30:05 2020 +0200
+++ b/src/testdir/test_vim9_func.vim Tue Jun 30 13:45:06 2020 +0200
@@ -837,6 +837,22 @@
837837 res = [1, 2, 3]->sort()
838838 enddef
839839
840+def Test_getqflist_return_type()
841+ let l = getqflist()
842+ assert_equal([], l)
843+
844+ let d = getqflist(#{items: 0})
845+ assert_equal(#{items: []}, d)
846+enddef
847+
848+def Test_getloclist_return_type()
849+ let l = getloclist(1)
850+ assert_equal([], l)
851+
852+ let d = getloclist(1, #{items: 0})
853+ assert_equal(#{items: []}, d)
854+enddef
855+
840856 def Line_continuation_in_def(dir: string = ''): string
841857 let path: string = empty(dir)
842858 \ ? 'empty'
diff -r 949a9ea0cfce -r d69ead03ba93 src/version.c
--- a/src/version.c Mon Jun 29 23:30:05 2020 +0200
+++ b/src/version.c Tue Jun 30 13:45:06 2020 +0200
@@ -755,6 +755,8 @@
755755 static int included_patches[] =
756756 { /* Add new patch number below this line */
757757 /**/
758+ 1096,
759+/**/
758760 1095,
759761 /**/
760762 1094,
Show on old repository browser