To: vim_dev@googlegroups.com Subject: Patch 8.2.1302 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1302 Problem: Vim9: varargs arg after optional arg does not work Solution: Check for the "..." first. (issue #6507) Files: src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1301/src/vim9compile.c 2020-07-26 18:16:54.541064949 +0200 --- src/vim9compile.c 2020-07-26 18:26:57.042834425 +0200 *************** *** 2106,2121 **** first_optional = argcount; ++p; } - else if (first_optional != -1) - { - emsg(_("E1007: mandatory argument after optional argument")); - return &t_any; - } else if (STRNCMP(p, "...", 3) == 0) { flags |= TTFLAG_VARARGS; p += 3; } arg_type[argcount++] = parse_type(&p, type_gap); --- 2106,2121 ---- first_optional = argcount; ++p; } else if (STRNCMP(p, "...", 3) == 0) { flags |= TTFLAG_VARARGS; p += 3; } + else if (first_optional != -1) + { + emsg(_("E1007: mandatory argument after optional argument")); + return &t_any; + } arg_type[argcount++] = parse_type(&p, type_gap); *** ../vim-8.2.1301/src/testdir/test_vim9_func.vim 2020-07-26 18:16:54.541064949 +0200 --- src/testdir/test_vim9_func.vim 2020-07-26 18:32:19.345264178 +0200 *************** *** 376,381 **** --- 376,403 ---- assert_equal([1, 2, 3], g:echo) END CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + def OptAndVar(nr: number, opt = 12, ...l: list): number + g:optarg = opt + g:listarg = l + return nr + enddef + let Funcref: func(number, ?number, ...list): number = function('OptAndVar') + assert_equal(10, Funcref(10)) + assert_equal(12, g:optarg) + assert_equal([], g:listarg) + + assert_equal(11, Funcref(11, 22)) + assert_equal(22, g:optarg) + assert_equal([], g:listarg) + + assert_equal(17, Funcref(17, 18, 1, 2, 3)) + assert_equal(18, g:optarg) + assert_equal([1, 2, 3], g:listarg) + END + CheckScriptSuccess(lines) enddef let SomeFunc = function('len') *** ../vim-8.2.1301/src/version.c 2020-07-26 18:16:54.541064949 +0200 --- src/version.c 2020-07-26 18:27:54.406618377 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1302, /**/ -- You are only young once, but you can stay immature indefinitely. /// 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 ///