]> granicus.if.org Git - vim/commitdiff
patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg v8.2.1397
authorBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 15:55:49 +0000 (17:55 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 15:55:49 +0000 (17:55 +0200)
Problem:    Vim9: return type of maparg() not adjusted for fourth argument.
Solution:   Check if fourth argument is present. (closes #6645)

src/evalfunc.c
src/testdir/test_maparg.vim
src/version.c

index a421690e499e4eb2ef9f41cb831e57397212fb6b..5607ef9e5ba8a2b5490c527b40195d3d3f0a8f1d 100644 (file)
@@ -402,6 +402,15 @@ ret_getreg(int argcount, type_T **argtypes UNUSED)
     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},
index 81e057adcae14f6c1ced3a0cff252493cdd52cbb..3b61ff6cf78586e150d8f0b5a2a9c596c6d28c94 100644 (file)
@@ -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<any> = 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'))
index 8649ca89654fa2ba1943125b874172604dc61a74..b67d3c3dac0003d4949336bd65eaad1d01b9e012 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1397,
 /**/
     1396,
 /**/