To: vim_dev@googlegroups.com Subject: Patch 7.4.1564 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1564 Problem: An empty list in function() causes an error. Solution: Handle an empty list like there is no list of arguments. Files: src/eval.c, src/testdir/test_partial.vim *** ../vim-7.4.1563/src/eval.c 2016-03-14 23:04:49.698923062 +0100 --- src/eval.c 2016-03-15 12:30:04.205184835 +0100 *************** *** 11786,11791 **** --- 11786,11795 ---- EMSG2(_("E700: Unknown function: %s"), s); else { + int dict_idx = 0; + int arg_idx = 0; + list_T *list = NULL; + if (STRNCMP(s, "s:", 2) == 0 || STRNCMP(s, "", 5) == 0) { char sid_buf[25]; *************** *** 11808,11817 **** if (argvars[1].v_type != VAR_UNKNOWN) { - partial_T *pt; - int dict_idx = 0; - int arg_idx = 0; - if (argvars[2].v_type != VAR_UNKNOWN) { /* function(name, [args], dict) */ --- 11812,11817 ---- *************** *** 11824,11850 **** else /* function(name, [args]) */ arg_idx = 1; ! if (dict_idx > 0 && (argvars[dict_idx].v_type != VAR_DICT ! || argvars[dict_idx].vval.v_dict == NULL)) { ! EMSG(_("E922: expected a dict")); ! vim_free(name); ! return; } ! if (arg_idx > 0 && (argvars[arg_idx].v_type != VAR_LIST ! || argvars[arg_idx].vval.v_list == NULL)) { ! EMSG(_("E923: Second argument of function() must be a list or a dict")); ! vim_free(name); ! return; } - pt = (partial_T *)alloc_clear(sizeof(partial_T)); if (pt != NULL) { if (arg_idx > 0) { - list_T *list = argvars[arg_idx].vval.v_list; listitem_T *li; int i = 0; --- 11824,11861 ---- else /* function(name, [args]) */ arg_idx = 1; ! if (dict_idx > 0) { ! if (argvars[dict_idx].v_type != VAR_DICT) ! { ! EMSG(_("E922: expected a dict")); ! vim_free(name); ! return; ! } ! if (argvars[dict_idx].vval.v_dict == NULL) ! dict_idx = 0; } ! if (arg_idx > 0) { ! if (argvars[arg_idx].v_type != VAR_LIST) ! { ! EMSG(_("E923: Second argument of function() must be a list or a dict")); ! vim_free(name); ! return; ! } ! list = argvars[arg_idx].vval.v_list; ! if (list == NULL || list->lv_len == 0) ! arg_idx = 0; } + } + if (dict_idx > 0 || arg_idx > 0) + { + partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T)); if (pt != NULL) { if (arg_idx > 0) { listitem_T *li; int i = 0; *** ../vim-7.4.1563/src/testdir/test_partial.vim 2016-03-15 11:05:40.565905732 +0100 --- src/testdir/test_partial.vim 2016-03-15 12:34:11.102610386 +0100 *************** *** 19,24 **** --- 19,27 ---- call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb = function('MyFunc', []) + call assert_equal("a/b/c", Cb("a", "b", "c")) + let Sort = function('MySort', [1]) call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) let Sort = function('MySort', [0]) *************** *** 34,43 **** let Cb = function('MyDictFunc', ["foo", "bar"], dict) call assert_equal("hello/foo/bar", Cb()) call assert_fails('Cb("xxx")', 'E492:') let Cb = function('MyDictFunc', ["foo"], dict) call assert_equal("hello/foo/xxx", Cb("xxx")) call assert_fails('Cb()', 'E492:') let Cb = function('MyDictFunc', dict) call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) ! call assert_fails('Cb()', 'E492:') endfunc --- 37,52 ---- let Cb = function('MyDictFunc', ["foo", "bar"], dict) call assert_equal("hello/foo/bar", Cb()) call assert_fails('Cb("xxx")', 'E492:') + let Cb = function('MyDictFunc', ["foo"], dict) call assert_equal("hello/foo/xxx", Cb("xxx")) call assert_fails('Cb()', 'E492:') + + let Cb = function('MyDictFunc', [], dict) + call assert_equal("hello/ttt/xxx", Cb("ttt", "xxx")) + call assert_fails('Cb("yyy")', 'E492:') + let Cb = function('MyDictFunc', dict) call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) ! call assert_fails('Cb("fff")', 'E492:') endfunc *** ../vim-7.4.1563/src/version.c 2016-03-15 11:05:40.569905689 +0100 --- src/version.c 2016-03-15 12:34:23.458481555 +0100 *************** *** 745,746 **** --- 745,748 ---- { /* Add new patch number below this line */ + /**/ + 1564, /**/ -- A fine is a tax for doing wrong. A tax is a fine for doing well. /// 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 ///