Skip to content

Commit 5c29154

Browse files
committed
patch 7.4.1608
Problem: string() doesn't handle a partial. Solution: Make a string from a partial.
1 parent f0e86a0 commit 5c29154

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

src/eval.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7897,9 +7897,49 @@ tv2string(
78977897
*tofree = string_quote(tv->vval.v_string, TRUE);
78987898
return *tofree;
78997899
case VAR_PARTIAL:
7900-
*tofree = string_quote(tv->vval.v_partial == NULL ? NULL
7901-
: tv->vval.v_partial->pt_name, TRUE);
7902-
return *tofree;
7900+
{
7901+
partial_T *pt = tv->vval.v_partial;
7902+
char_u *fname = string_quote(pt == NULL ? NULL
7903+
: pt->pt_name, FALSE);
7904+
garray_T ga;
7905+
int i;
7906+
char_u *tf;
7907+
7908+
ga_init2(&ga, 1, 100);
7909+
ga_concat(&ga, (char_u *)"function(");
7910+
if (fname != NULL)
7911+
{
7912+
ga_concat(&ga, fname);
7913+
vim_free(fname);
7914+
}
7915+
if (pt != NULL && pt->pt_argc > 0)
7916+
{
7917+
ga_concat(&ga, (char_u *)", [");
7918+
for (i = 0; i < pt->pt_argc; ++i)
7919+
{
7920+
if (i > 0)
7921+
ga_concat(&ga, (char_u *)", ");
7922+
ga_concat(&ga,
7923+
tv2string(&pt->pt_argv[i], &tf, numbuf, copyID));
7924+
vim_free(tf);
7925+
}
7926+
ga_concat(&ga, (char_u *)"]");
7927+
}
7928+
if (pt != NULL && pt->pt_dict != NULL)
7929+
{
7930+
typval_T dtv;
7931+
7932+
ga_concat(&ga, (char_u *)", ");
7933+
dtv.v_type = VAR_DICT;
7934+
dtv.vval.v_dict = pt->pt_dict;
7935+
ga_concat(&ga, tv2string(&dtv, &tf, numbuf, copyID));
7936+
vim_free(tf);
7937+
}
7938+
ga_concat(&ga, (char_u *)")");
7939+
7940+
*tofree = ga.ga_data;
7941+
return *tofree;
7942+
}
79037943
case VAR_STRING:
79047944
*tofree = string_quote(tv->vval.v_string, FALSE);
79057945
return *tofree;

src/testdir/test_partial.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,17 @@ func Test_partial_exists()
156156
let lF = [F]
157157
call assert_true(exists('*lF[0]'))
158158
endfunc
159+
160+
func Test_partial_string()
161+
let F = function('MyFunc')
162+
call assert_equal("function('MyFunc')", string(F))
163+
let F = function('MyFunc', ['foo'])
164+
call assert_equal("function('MyFunc', ['foo'])", string(F))
165+
let F = function('MyFunc', ['foo', 'bar'])
166+
call assert_equal("function('MyFunc', ['foo', 'bar'])", string(F))
167+
let d = {'one': 1}
168+
let F = function('MyFunc', d)
169+
call assert_equal("function('MyFunc', {'one': 1})", string(F))
170+
let F = function('MyFunc', ['foo'], d)
171+
call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F))
172+
endfunc

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+
1608,
751753
/**/
752754
1607,
753755
/**/

0 commit comments

Comments
 (0)