]> granicus.if.org Git - vim/commitdiff
patch 8.2.1380: Vim9: return type of getreg() is always a string v8.2.1380
authorBram Moolenaar <Bram@vim.org>
Thu, 6 Aug 2020 19:26:59 +0000 (21:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 6 Aug 2020 19:26:59 +0000 (21:26 +0200)
Problem:    Vim9: return type of getreg() is always a string.
Solution:   Use list of strings when there are three arguments. (closes #6633)

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

index a631fd9c8449edc2949c9b1d23b1fc45e596b371..a421690e499e4eb2ef9f41cb831e57397212fb6b 100644 (file)
@@ -393,6 +393,15 @@ ret_remove(int argcount UNUSED, type_T **argtypes)
     return &t_any;
 }
 
+    static type_T *
+ret_getreg(int argcount, type_T **argtypes UNUSED)
+{
+    // Assume that if the third argument is passed it's non-zero
+    if (argcount == 3)
+       return &t_list_string;
+    return &t_string;
+}
+
 static type_T *ret_f_function(int argcount, type_T **argtypes);
 
 /*
@@ -641,7 +650,7 @@ static funcentry_T global_functions[] =
     {"getpid",         0, 0, 0,          ret_number,   f_getpid},
     {"getpos",         1, 1, FEARG_1,    ret_list_number,      f_getpos},
     {"getqflist",      0, 1, 0,          ret_list_or_dict_0,   f_getqflist},
-    {"getreg",         0, 3, FEARG_1,    ret_string,   f_getreg},
+    {"getreg",         0, 3, FEARG_1,    ret_getreg,   f_getreg},
     {"getreginfo",     0, 1, FEARG_1,    ret_dict_any, f_getreginfo},
     {"getregtype",     0, 1, FEARG_1,    ret_string,   f_getregtype},
     {"gettabinfo",     0, 1, FEARG_1,    ret_list_dict_any,    f_gettabinfo},
index d0248369ce324707998e4b729746d5d7defaa7be..649ef4806921b96e39de1c6f3a6e84fbe1065035 100644 (file)
@@ -1202,6 +1202,12 @@ def Test_filter_return_type()
   assert_equal(6, res)
 enddef
 
+def Test_getreg_return_type()
+  let s1: string = getreg('"')
+  let s2: string = getreg('"', 1)
+  let s3: list<string> = getreg('"', 1, 1)
+enddef
+
 def Wrong_dict_key_type(items: list<number>): list<number>
   return filter(items, {_, val -> get({val: 1}, 'x')})
 enddef
index 2ae04a974aa5faa371921021a6e4d90a82d2c802..3b5fedc9045a0f8652ba48d4ad3e4135a1bf7d58 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1380,
 /**/
     1379,
 /**/