To: vim_dev@googlegroups.com Subject: Patch 8.2.2747 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2747 Problem: Vim9: not always an error for too many function arguments. Solution: Check for getting too many arguments. Files: src/vim9execute.c, src/testdir/test_vim9_func.vim, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.2746/src/vim9execute.c 2021-04-10 13:33:44.441064014 +0200 --- src/vim9execute.c 2021-04-10 20:02:36.013829911 +0200 *************** *** 1336,1341 **** --- 1336,1351 ---- ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10); ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10); + idx = argc - ufunc->uf_args.ga_len; + if (idx > 0 && ufunc->uf_va_name == NULL) + { + if (idx == 1) + emsg(_(e_one_argument_too_many)); + else + semsg(_(e_nr_arguments_too_many), idx); + return FAIL; + } + // Put arguments on the stack, but no more than what the function expects. // A lambda can be called with more arguments than it uses. for (idx = 0; idx < argc *** ../vim-8.2.2746/src/testdir/test_vim9_func.vim 2021-04-10 17:17:33.435942828 +0200 --- src/testdir/test_vim9_func.vim 2021-04-10 20:01:07.050086654 +0200 *************** *** 2102,2108 **** var lines =<< trim END vim9script var script = 'test' ! assert_equal(['test'], map(['one'], () => script)) END CheckScriptSuccess(lines) enddef --- 2102,2108 ---- var lines =<< trim END vim9script var script = 'test' ! assert_equal(['test'], map(['one'], (_, _) => script)) END CheckScriptSuccess(lines) enddef *************** *** 2355,2361 **** var x = ['a', 'b', 'c'] if 1 var y = 'x' ! map(x, () => y) endif var z = x assert_equal(['x', 'x', 'x'], z) --- 2355,2361 ---- var x = ['a', 'b', 'c'] if 1 var y = 'x' ! map(x, (_, _) => y) endif var z = x assert_equal(['x', 'x', 'x'], z) *************** *** 2654,2659 **** --- 2654,2670 ---- CheckDefAndScriptFailure(lines, 'E1181:', 1) enddef + def Test_too_many_arguments() + var lines =<< trim END + echo [0, 1, 2]->map(() => 123) + END + CheckDefExecAndScriptFailure(lines, 'E1106: 2 arguments too many', 1) + + lines =<< trim END + echo [0, 1, 2]->map((_) => 123) + END + CheckDefExecAndScriptFailure(lines, 'E1106: One argument too many', 1) + enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.2746/src/testdir/test_vim9_builtin.vim 2021-04-05 13:36:30.155371201 +0200 --- src/testdir/test_vim9_builtin.vim 2021-04-10 20:04:47.549392009 +0200 *************** *** 506,512 **** enddef def Test_filter_return_type() ! var l = filter([1, 2, 3], () => 1) var res = 0 for n in l res += n --- 506,512 ---- enddef def Test_filter_return_type() ! var l = filter([1, 2, 3], (_, _) => 1) var res = 0 for n in l res += n *************** *** 516,522 **** def Test_filter_missing_argument() var dict = {aa: [1], ab: [2], ac: [3], de: [4]} ! var res = dict->filter((k) => k =~ 'a' && k !~ 'b') res->assert_equal({aa: [1], ac: [3]}) enddef --- 516,522 ---- def Test_filter_missing_argument() var dict = {aa: [1], ab: [2], ac: [3], de: [4]} ! var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b') res->assert_equal({aa: [1], ac: [3]}) enddef *** ../vim-8.2.2746/src/version.c 2021-04-10 18:21:27.001205481 +0200 --- src/version.c 2021-04-10 19:50:38.127335903 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2747, /**/ -- Warning label on a superhero Halloween costume: "Caution: Cape does not enable user to fly." /// 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 ///