Skip to content

Commit 4a6d1b6

Browse files
committed
patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Problem: Vim9: return type of maparg() not adjusted for fourth argument. Solution: Check if fourth argument is present. (closes #6645)
1 parent 5a849da commit 4a6d1b6

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/evalfunc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ ret_getreg(int argcount, type_T **argtypes UNUSED)
402402
return &t_string;
403403
}
404404

405+
static type_T *
406+
ret_maparg(int argcount, type_T **argtypes UNUSED)
407+
{
408+
// Assume that if the fourth argument is passed it's non-zero
409+
if (argcount == 4)
410+
return &t_dict_any;
411+
return &t_string;
412+
}
413+
405414
static type_T *ret_f_function(int argcount, type_T **argtypes);
406415

407416
/*
@@ -729,7 +738,7 @@ static funcentry_T global_functions[] =
729738
#endif
730739
},
731740
{"map", 2, 2, FEARG_1, ret_any, f_map},
732-
{"maparg", 1, 4, FEARG_1, ret_string, f_maparg},
741+
{"maparg", 1, 4, FEARG_1, ret_maparg, f_maparg},
733742
{"mapcheck", 1, 3, FEARG_1, ret_string, f_mapcheck},
734743
{"mapset", 3, 3, FEARG_1, ret_void, f_mapset},
735744
{"match", 2, 4, FEARG_1, ret_any, f_match},

src/testdir/test_maparg.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ func Test_maparg()
8181
abclear
8282
endfunc
8383

84+
def Test_vim9_maparg()
85+
nmap { w
86+
let one: string = maparg('{')
87+
assert_equal('w', one)
88+
let two: string = maparg('{', 'n')
89+
assert_equal('w', two)
90+
let three: string = maparg('{', 'n', 0)
91+
assert_equal('w', three)
92+
let four: dict<any> = maparg('{', 'n', 0, 1)
93+
call assert_equal(['{', 'w', 'n'], [four.lhs, four.rhs, four.mode])
94+
nunmap {
95+
enddef
96+
8497
func Test_mapcheck()
8598
call assert_equal('', mapcheck('a'))
8699
call assert_equal('', mapcheck('abc'))

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1397,
757759
/**/
758760
1396,
759761
/**/

0 commit comments

Comments
 (0)