Skip to content

Commit 97f227d

Browse files
committed
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Problem: Vim9: type of partial is wrong when it has arguments. Solution: Subtract arguments from the count. (issue #8492)
1 parent b7480cd commit 97f227d

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/testdir/test_vim9_assign.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,16 @@ def Test_assignment_list()
661661
CheckDefExecAndScriptFailure(lines, 'E1012:', 5)
662662
enddef
663663

664-
def PartFunc(b: bool): string
664+
def PartFuncBool(b: bool): string
665665
return 'done'
666666
enddef
667667

668668
def Test_assignment_partial()
669-
var Partial: func(): string = function(PartFunc, [true])
670-
assert_equal('done', Partial())
669+
var lines =<< trim END
670+
var Partial: func(): string = function(PartFuncBool, [true])
671+
assert_equal('done', Partial())
672+
END
673+
CheckDefAndScriptSuccess(lines)
671674
enddef
672675

673676
def Test_assignment_list_any_index()

src/userfunc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ call_func(
31033103
int argv_clear = 0;
31043104
int argv_base = 0;
31053105
partial_T *partial = funcexe->partial;
3106+
type_T check_type;
31063107

31073108
// Initialize rettv so that it is safe for caller to invoke clear_tv(rettv)
31083109
// even when call_func() returns FAIL.
@@ -3146,6 +3147,16 @@ call_func(
31463147
argv[i + argv_clear] = argvars_in[i];
31473148
argvars = argv;
31483149
argcount = partial->pt_argc + argcount_in;
3150+
3151+
if (funcexe->check_type != NULL)
3152+
{
3153+
// Now funcexe->check_type is missing the added arguments, make
3154+
// a copy of the type with the correction.
3155+
check_type = *funcexe->check_type;
3156+
funcexe->check_type = &check_type;
3157+
check_type.tt_argcount += partial->pt_argc;
3158+
check_type.tt_min_argcount += partial->pt_argc;
3159+
}
31493160
}
31503161
}
31513162

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3105,
758760
/**/
759761
3104,
760762
/**/

src/vim9type.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,20 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
355355
if (ufunc->uf_func_type == NULL)
356356
set_function_type(ufunc);
357357
if (ufunc->uf_func_type != NULL)
358+
{
359+
if (tv->v_type == VAR_PARTIAL
360+
&& tv->vval.v_partial->pt_argc > 0)
361+
{
362+
type = get_type_ptr(type_gap);
363+
if (type == NULL)
364+
return NULL;
365+
*type = *ufunc->uf_func_type;
366+
type->tt_argcount -= tv->vval.v_partial->pt_argc;
367+
type->tt_min_argcount -= tv->vval.v_partial->pt_argc;
368+
return type;
369+
}
358370
return ufunc->uf_func_type;
371+
}
359372
}
360373
}
361374

0 commit comments

Comments
 (0)