changeset 30289:085406413994 v9.0.0480

patch 9.0.0480: cannot use a :def varargs function with substitute() Commit: https://github.com/vim/vim/commit/abd58d8aee7fec2b9e07c829eb925b0a1f7118db Author: zeertzjq <zeertzjq@outlook.com> Date: Fri Sep 16 16:06:32 2022 +0100 patch 9.0.0480: cannot use a :def varargs function with substitute() Problem: Cannot use a :def varargs function with substitute(). Solution: Use has_varargs(). (closes https://github.com/vim/vim/issues/11146)
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Sep 2022 17:15:03 +0200
parents a0c20aacc4e3
children e5d24015e8c5
files src/regexp.c src/testdir/test_substitute.vim src/version.c
diffstat 3 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -1824,7 +1824,7 @@ fill_submatch_list(int argc UNUSED, typv
     char_u	*s;
     typval_T	*listarg = argv + argskip;
 
-    if (!fp->uf_varargs && fp->uf_args.ga_len <= argskip)
+    if (!has_varargs(fp) && fp->uf_args.ga_len <= argskip)
 	// called function doesn't take a submatches argument
 	return argskip;
 
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -442,6 +442,9 @@ endfunc
 func SubReplacerVar(text, ...)
   return a:text .. a:1[0] .. a:text
 endfunc
+def SubReplacerVar9(text: string, ...args: list<list<string>>): string
+  return text .. args[0][0] .. text
+enddef
 func SubReplacer20(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, submatches)
   return a:t3 .. a:submatches[0] .. a:t11
 endfunc
@@ -449,6 +452,7 @@ endfunc
 func Test_substitute_partial()
   call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g'))
   call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar', ['foo']), 'g'))
+  call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar9', ['foo']), 'g'))
 
   " 19 arguments plus one is just OK
   let Replacer = function('SubReplacer20', repeat(['foo'], 19))
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    480,
+/**/
     479,
 /**/
     478,