# HG changeset patch # User Bram Moolenaar # Date 1596902404 -7200 # Node ID f27187782dc67859fd93ec771ca50a9e2fce5b6d # Parent 48d2a443fb3d4fe102b1aaf1906458059cae42d3 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg Commit: https://github.com/vim/vim/commit/4a6d1b660fcea67931202527ad2852da55d26d49 Author: Bram Moolenaar Date: Sat Aug 8 17:55:49 2020 +0200 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 https://github.com/vim/vim/issues/6645) diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -402,6 +402,15 @@ ret_getreg(int argcount, type_T **argtyp return &t_string; } + static type_T * +ret_maparg(int argcount, type_T **argtypes UNUSED) +{ + // Assume that if the fourth argument is passed it's non-zero + if (argcount == 4) + return &t_dict_any; + return &t_string; +} + static type_T *ret_f_function(int argcount, type_T **argtypes); /* @@ -729,7 +738,7 @@ static funcentry_T global_functions[] = #endif }, {"map", 2, 2, FEARG_1, ret_any, f_map}, - {"maparg", 1, 4, FEARG_1, ret_string, f_maparg}, + {"maparg", 1, 4, FEARG_1, ret_maparg, f_maparg}, {"mapcheck", 1, 3, FEARG_1, ret_string, f_mapcheck}, {"mapset", 3, 3, FEARG_1, ret_void, f_mapset}, {"match", 2, 4, FEARG_1, ret_any, f_match}, diff --git a/src/testdir/test_maparg.vim b/src/testdir/test_maparg.vim --- a/src/testdir/test_maparg.vim +++ b/src/testdir/test_maparg.vim @@ -81,6 +81,19 @@ func Test_maparg() abclear endfunc +def Test_vim9_maparg() + nmap { w + let one: string = maparg('{') + assert_equal('w', one) + let two: string = maparg('{', 'n') + assert_equal('w', two) + let three: string = maparg('{', 'n', 0) + assert_equal('w', three) + let four: dict = maparg('{', 'n', 0, 1) + call assert_equal(['{', 'w', 'n'], [four.lhs, four.rhs, four.mode]) + nunmap { +enddef + func Test_mapcheck() call assert_equal('', mapcheck('a')) call assert_equal('', mapcheck('abc')) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1397, +/**/ 1396, /**/ 1395,