1
0
forked from aniani/vim

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 #11146)
This commit is contained in:
zeertzjq 2022-09-16 16:06:32 +01:00 committed by Bram Moolenaar
parent 1aea184a0d
commit abd58d8aee
3 changed files with 7 additions and 1 deletions

View File

@ -1824,7 +1824,7 @@ fill_submatch_list(int argc UNUSED, typval_T *argv, int argskip, ufunc_T *fp)
char_u *s; char_u *s;
typval_T *listarg = argv + argskip; 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 // called function doesn't take a submatches argument
return argskip; return argskip;

View File

@ -442,6 +442,9 @@ endfunc
func SubReplacerVar(text, ...) func SubReplacerVar(text, ...)
return a:text .. a:1[0] .. a:text return a:text .. a:1[0] .. a:text
endfunc 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) 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 return a:t3 .. a:submatches[0] .. a:t11
endfunc endfunc
@ -449,6 +452,7 @@ endfunc
func Test_substitute_partial() func Test_substitute_partial()
call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g')) 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('SubReplacerVar', ['foo']), 'g'))
call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar9', ['foo']), 'g'))
" 19 arguments plus one is just OK " 19 arguments plus one is just OK
let Replacer = function('SubReplacer20', repeat(['foo'], 19)) let Replacer = function('SubReplacer20', repeat(['foo'], 19))

View File

@ -703,6 +703,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
480,
/**/ /**/
479, 479,
/**/ /**/