To: vim_dev@googlegroups.com Subject: Patch 8.2.1096 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1096 Problem: Vim9: return type of getqflist() is wrong. Solution: Let the return type depend on the arguments. Also for getloclist(). (closes #6367) Files: src/evalfunc.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1095/src/evalfunc.c 2020-06-29 19:55:54.885328478 +0200 --- src/evalfunc.c 2020-06-30 13:15:05.045003874 +0200 *************** *** 347,352 **** --- 347,376 ---- 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,600 **** {"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}, {"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}, {"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}, --- 612,624 ---- {"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_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_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}, *** ../vim-8.2.1095/src/testdir/test_vim9_func.vim 2020-06-22 19:38:59.928402805 +0200 --- src/testdir/test_vim9_func.vim 2020-06-30 13:20:31.519608201 +0200 *************** *** 837,842 **** --- 837,858 ---- 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' *** ../vim-8.2.1095/src/version.c 2020-06-29 23:18:39.731914331 +0200 --- src/version.c 2020-06-30 13:19:50.459785376 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1096, /**/ -- To keep milk from turning sour: Keep it in the cow. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///