Skip to content

Commit 8a1bb04

Browse files
committed
patch 7.4.1586
Problem: Nesting partials doesn't work. Solution: Append arguments. (Ken Takata)
1 parent d22a189 commit 8a1bb04

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/eval.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11814,6 +11814,7 @@ f_function(typval_T *argvars, typval_T *rettv)
1181411814
char_u *s;
1181511815
char_u *name;
1181611816
int use_string = FALSE;
11817+
partial_T *arg_pt = NULL;
1181711818

1181811819
if (argvars[0].v_type == VAR_FUNC)
1181911820
{
@@ -11822,8 +11823,11 @@ f_function(typval_T *argvars, typval_T *rettv)
1182211823
}
1182311824
else if (argvars[0].v_type == VAR_PARTIAL
1182411825
&& argvars[0].vval.v_partial != NULL)
11826+
{
1182511827
/* function(dict.MyFunc, [arg]) */
11826-
s = argvars[0].vval.v_partial->pt_name;
11828+
arg_pt = argvars[0].vval.v_partial;
11829+
s = arg_pt->pt_name;
11830+
}
1182711831
else
1182811832
{
1182911833
/* function('MyFunc', [arg], dict) */
@@ -11901,19 +11905,27 @@ f_function(typval_T *argvars, typval_T *rettv)
1190111905
arg_idx = 0;
1190211906
}
1190311907
}
11904-
if (dict_idx > 0 || arg_idx > 0)
11908+
if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL)
1190511909
{
1190611910
partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T));
1190711911

11912+
/* result is a VAR_PARTIAL */
1190811913
if (pt != NULL)
1190911914
{
11910-
if (arg_idx > 0)
11915+
if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0))
1191111916
{
1191211917
listitem_T *li;
1191311918
int i = 0;
11914-
11919+
int arg_len = 0;
11920+
int lv_len = 0;
11921+
11922+
if (arg_pt != NULL)
11923+
arg_len = arg_pt->pt_argc;
11924+
if (list != NULL)
11925+
lv_len = list->lv_len;
11926+
pt->pt_argc = arg_len + lv_len;
1191511927
pt->pt_argv = (typval_T *)alloc(
11916-
sizeof(typval_T) * list->lv_len);
11928+
sizeof(typval_T) * pt->pt_argc);
1191711929
if (pt->pt_argv == NULL)
1191811930
{
1191911931
vim_free(pt);
@@ -11922,9 +11934,12 @@ f_function(typval_T *argvars, typval_T *rettv)
1192211934
}
1192311935
else
1192411936
{
11925-
pt->pt_argc = list->lv_len;
11926-
for (li = list->lv_first; li != NULL; li = li->li_next)
11927-
copy_tv(&li->li_tv, &pt->pt_argv[i++]);
11937+
for (i = 0; i < arg_len; i++)
11938+
copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]);
11939+
if (lv_len > 0)
11940+
for (li = list->lv_first; li != NULL;
11941+
li = li->li_next)
11942+
copy_tv(&li->li_tv, &pt->pt_argv[i++]);
1192811943
}
1192911944
}
1193011945

@@ -11935,10 +11950,11 @@ f_function(typval_T *argvars, typval_T *rettv)
1193511950
pt->pt_dict = argvars[dict_idx].vval.v_dict;
1193611951
++pt->pt_dict->dv_refcount;
1193711952
}
11938-
else if (argvars[0].v_type == VAR_PARTIAL)
11953+
else if (arg_pt != NULL)
1193911954
{
11940-
pt->pt_dict = argvars[0].vval.v_partial->pt_dict;
11941-
++pt->pt_dict->dv_refcount;
11955+
pt->pt_dict = arg_pt->pt_dict;
11956+
if (pt->pt_dict != NULL)
11957+
++pt->pt_dict->dv_refcount;
1194211958
}
1194311959

1194411960
pt->pt_refcount = 1;
@@ -11950,6 +11966,7 @@ f_function(typval_T *argvars, typval_T *rettv)
1195011966
}
1195111967
else
1195211968
{
11969+
/* result is a VAR_FUNC */
1195311970
rettv->v_type = VAR_FUNC;
1195411971
rettv->vval.v_string = name;
1195511972
func_ref(name);

src/testdir/test_partial.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ func Test_partial_args()
2020
call Cb("zzz")
2121
call assert_equal("foo/bar/xxx", Cb("xxx"))
2222
call assert_equal("foo/bar/yyy", call(Cb, ["yyy"]))
23+
let Cb2 = function(Cb)
24+
call assert_equal("foo/bar/zzz", Cb2("zzz"))
25+
let Cb3 = function(Cb, ["www"])
26+
call assert_equal("foo/bar/www", Cb3())
2327

2428
let Cb = function('MyFunc', [])
2529
call assert_equal("a/b/c", Cb("a", "b", "c"))
30+
let Cb2 = function(Cb, [])
31+
call assert_equal("a/b/d", Cb2("a", "b", "d"))
32+
let Cb3 = function(Cb, ["a", "b"])
33+
call assert_equal("a/b/e", Cb3("e"))
2634

2735
let Sort = function('MySort', [1])
2836
call assert_equal([1, 2, 3], sort([3, 1, 2], Sort))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1586,
751753
/**/
752754
1585,
753755
/**/

0 commit comments

Comments
 (0)