To: vim_dev@googlegroups.com Subject: Patch 8.2.3872 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3872 Problem: Vim9: finddir() and uniq() return types can be more specific. Solution: Adjust the return type. Files: src/evalfunc.c, src/testdir/vim9.vim, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.3871/src/evalfunc.c 2021-12-21 12:32:13.296529989 +0000 --- src/evalfunc.c 2021-12-22 18:35:57.036730249 +0000 *************** *** 1033,1038 **** --- 1033,1047 ---- } return &t_any; } + // for finddir() + static type_T * + ret_finddir(int argcount, type_T **argtypes UNUSED) + { + if (argcount < 3) + return &t_string; + // Depending on the count would be a string or a list of strings. + return &t_any; + } /* * Used for getqflist(): returns list if there is no argument, dict if there is *************** *** 1431,1437 **** {"filter", 2, 2, FEARG_1, arg2_mapfilter, ret_first_arg, f_filter}, {"finddir", 1, 3, FEARG_1, arg3_string_string_number, ! ret_any, f_finddir}, {"findfile", 1, 3, FEARG_1, arg3_string_string_number, ret_any, f_findfile}, {"flatten", 1, 2, FEARG_1, arg2_list_any_number, --- 1440,1446 ---- {"filter", 2, 2, FEARG_1, arg2_mapfilter, ret_first_arg, f_filter}, {"finddir", 1, 3, FEARG_1, arg3_string_string_number, ! ret_finddir, f_finddir}, {"findfile", 1, 3, FEARG_1, arg3_string_string_number, ret_any, f_findfile}, {"flatten", 1, 2, FEARG_1, arg2_list_any_number, *************** *** 2291,2297 **** {"undotree", 0, 0, 0, NULL, ret_dict_any, f_undotree}, {"uniq", 1, 3, FEARG_1, arg13_sortuniq, ! ret_list_any, f_uniq}, {"values", 1, 1, FEARG_1, arg1_dict_any, ret_list_any, f_values}, {"virtcol", 1, 1, FEARG_1, arg1_string_or_list_any, --- 2300,2306 ---- {"undotree", 0, 0, 0, NULL, ret_dict_any, f_undotree}, {"uniq", 1, 3, FEARG_1, arg13_sortuniq, ! ret_first_arg, f_uniq}, {"values", 1, 1, FEARG_1, arg1_dict_any, ret_list_any, f_values}, {"virtcol", 1, 1, FEARG_1, arg1_string_or_list_any, *** ../vim-8.2.3871/src/testdir/vim9.vim 2021-12-19 21:34:01.699292755 +0000 --- src/testdir/vim9.vim 2021-12-22 18:40:21.580333179 +0000 *************** *** 3,9 **** " Use a different file name for each run. let s:sequence = 1 ! " Check that "lines" inside a ":def" function has no error. func CheckDefSuccess(lines) let cwd = getcwd() let fname = 'XdefSuccess' .. s:sequence --- 3,9 ---- " Use a different file name for each run. let s:sequence = 1 ! " Check that "lines" inside a ":def" function has no error when called. func CheckDefSuccess(lines) let cwd = getcwd() let fname = 'XdefSuccess' .. s:sequence *************** *** 17,22 **** --- 17,35 ---- call delete(fname) delfunc! Func endtry + endfunc + + " Check that "lines" inside a ":def" function has no error when compiled. + func CheckDefCompileSuccess(lines) + let fname = 'XdefSuccess' .. s:sequence + let s:sequence += 1 + call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname) + try + exe 'so ' .. fname + finally + call delete(fname) + delfunc! Func + endtry endfunc " Check that "lines" inside ":def" results in an "error" message. *** ../vim-8.2.3871/src/testdir/test_vim9_builtin.vim 2021-12-20 09:36:20.101548272 +0000 --- src/testdir/test_vim9_builtin.vim 2021-12-22 18:44:36.375931177 +0000 *************** *** 1110,1115 **** --- 1110,1120 ---- CheckDefAndScriptFailure(['finddir("a", [])'], ['E1013: Argument 2: type mismatch, expected string but got list', 'E1174: String required for argument 2']) CheckDefAndScriptFailure(['finddir("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3']) finddir('abc', '')->assert_equal('') + + CheckDefFailure(['var s: list = finddir("foo")'], 'E1012: Type mismatch; expected list but got string') + CheckDefFailure(['var s: list = finddir("foo", "path")'], 'E1012: Type mismatch; expected list but got string') + # with third argument only runtime type checking + CheckDefCompileSuccess(['var s: list = finddir("foo", "path", 1)']) enddef def Test_findfile() *************** *** 4036,4041 **** --- 4041,4048 ---- def Test_uniq() CheckDefAndScriptFailure(['uniq("a")'], ['E1013: Argument 1: type mismatch, expected list but got string', 'E1211: List required for argument 1']) CheckDefAndScriptFailure(['uniq([1], "", [1])'], ['E1013: Argument 3: type mismatch, expected dict but got list', 'E1206: Dictionary required for argument 3']) + + CheckDefFailure(['var l: list = uniq(["a", "b"])'], 'E1012: Type mismatch; expected list but got list') enddef def Test_values() *** ../vim-8.2.3871/src/version.c 2021-12-22 18:19:22.602372473 +0000 --- src/version.c 2021-12-22 18:39:02.252454864 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3872, /**/ -- From "know your smileys": =):-) Uncle Sam /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///