Skip to content

Commit f78da4f

Browse files
committed
patch 8.2.3269: Vim9: wrong argument check for partial
Problem: Vim9: wrong argument check for partial. (Naohiro Ono) Solution: Handle getting return type without arguments. Correct the minimal number of arguments for what is included in the partial. (closes #8667)
1 parent 73b8b0a commit f78da4f

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

src/evalfunc.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -932,22 +932,27 @@ ret_first_arg(int argcount, type_T **argtypes)
932932
return &t_void;
933933
}
934934
static type_T *
935-
ret_repeat(int argcount UNUSED, type_T **argtypes)
935+
ret_repeat(int argcount, type_T **argtypes)
936936
{
937+
if (argcount == 0)
938+
return &t_any;
937939
if (argtypes[0] == &t_number)
938940
return &t_string;
939941
return argtypes[0];
940942
}
941943
// for map(): returns first argument but item type may differ
942944
static type_T *
943-
ret_first_cont(int argcount UNUSED, type_T **argtypes)
945+
ret_first_cont(int argcount, type_T **argtypes)
944946
{
945-
if (argtypes[0]->tt_type == VAR_LIST)
946-
return &t_list_any;
947-
if (argtypes[0]->tt_type == VAR_DICT)
948-
return &t_dict_any;
949-
if (argtypes[0]->tt_type == VAR_BLOB)
950-
return argtypes[0];
947+
if (argcount > 0)
948+
{
949+
if (argtypes[0]->tt_type == VAR_LIST)
950+
return &t_list_any;
951+
if (argtypes[0]->tt_type == VAR_DICT)
952+
return &t_dict_any;
953+
if (argtypes[0]->tt_type == VAR_BLOB)
954+
return argtypes[0];
955+
}
951956
return &t_any;
952957
}
953958

@@ -987,9 +992,9 @@ ret_argv(int argcount, type_T **argtypes UNUSED)
987992
}
988993

989994
static type_T *
990-
ret_remove(int argcount UNUSED, type_T **argtypes)
995+
ret_remove(int argcount, type_T **argtypes)
991996
{
992-
if (argtypes != NULL)
997+
if (argcount > 0)
993998
{
994999
if (argtypes[0]->tt_type == VAR_LIST
9951000
|| argtypes[0]->tt_type == VAR_DICT)
@@ -2446,6 +2451,7 @@ internal_func_get_argcount(int idx, int *argcount, int *min_argcount)
24462451
* Call the "f_retfunc" function to obtain the return type of function "idx".
24472452
* "argtypes" is the list of argument types or NULL when there are no
24482453
* arguments.
2454+
* "argcount" may be less than the actual count when only getting the type.
24492455
*/
24502456
type_T *
24512457
internal_func_ret_type(int idx, int argcount, type_T **argtypes)

src/testdir/test_vim9_func.vim

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,24 +2582,31 @@ def Test_invalid_function_name()
25822582
enddef
25832583

25842584
def Test_partial_call()
2585-
var Xsetlist = function('setloclist', [0])
2586-
Xsetlist([], ' ', {title: 'test'})
2587-
getloclist(0, {title: 1})->assert_equal({title: 'test'})
2585+
var lines =<< trim END
2586+
var Xsetlist: func
2587+
Xsetlist = function('setloclist', [0])
2588+
Xsetlist([], ' ', {title: 'test'})
2589+
getloclist(0, {title: 1})->assert_equal({title: 'test'})
2590+
2591+
Xsetlist = function('setloclist', [0, [], ' '])
2592+
Xsetlist({title: 'test'})
2593+
getloclist(0, {title: 1})->assert_equal({title: 'test'})
25882594

2589-
Xsetlist = function('setloclist', [0, [], ' '])
2590-
Xsetlist({title: 'test'})
2591-
getloclist(0, {title: 1})->assert_equal({title: 'test'})
2595+
Xsetlist = function('setqflist')
2596+
Xsetlist([], ' ', {title: 'test'})
2597+
getqflist({title: 1})->assert_equal({title: 'test'})
25922598

2593-
Xsetlist = function('setqflist')
2594-
Xsetlist([], ' ', {title: 'test'})
2595-
getqflist({title: 1})->assert_equal({title: 'test'})
2599+
Xsetlist = function('setqflist', [[], ' '])
2600+
Xsetlist({title: 'test'})
2601+
getqflist({title: 1})->assert_equal({title: 'test'})
25962602

2597-
Xsetlist = function('setqflist', [[], ' '])
2598-
Xsetlist({title: 'test'})
2599-
getqflist({title: 1})->assert_equal({title: 'test'})
2603+
var Len: func: number = function('len', ['word'])
2604+
assert_equal(4, Len())
26002605

2601-
var Len: func: number = function('len', ['word'])
2602-
assert_equal(4, Len())
2606+
var RepeatFunc = function('repeat', ['o'])
2607+
assert_equal('ooooo', RepeatFunc(5))
2608+
END
2609+
CheckDefAndScriptSuccess(lines)
26032610
enddef
26042611

26052612
def Test_cmd_modifier()

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+
3269,
758760
/**/
759761
3268,
760762
/**/

src/vim9type.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
378378
type->tt_type = tv->v_type;
379379
type->tt_argcount = argcount;
380380
type->tt_min_argcount = min_argcount;
381+
if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial->pt_argc > 0)
382+
{
383+
type->tt_argcount -= tv->vval.v_partial->pt_argc;
384+
type->tt_min_argcount -= tv->vval.v_partial->pt_argc;
385+
}
381386
type->tt_member = member_type;
382387

383388
return type;

0 commit comments

Comments
 (0)