]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1143: Vim9: return type of remove() is any v8.2.1143
authorBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 18:55:29 +0000 (20:55 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 18:55:29 +0000 (20:55 +0200)
Problem:    Vim9: return type of remove() is any.
Solution:   Use the member type of the first argument, if known.

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

index 65c34cd6a014c34d81ff15d984e7cdbbd81a39ad..83b878b37c57a475c5268af9fcb5b7bceaf8f59e 100644 (file)
@@ -382,6 +382,17 @@ ret_argv(int argcount, type_T **argtypes UNUSED)
     return &t_any;
 }
 
+    static type_T *
+ret_remove(int argcount UNUSED, type_T **argtypes)
+{
+    if (argtypes[0]->tt_type == VAR_LIST
+           || argtypes[0]->tt_type == VAR_DICT)
+       return argtypes[0]->tt_member;
+    if (argtypes[0]->tt_type == VAR_BLOB)
+       return &t_number;
+    return &t_any;
+}
+
 static type_T *ret_f_function(int argcount, type_T **argtypes);
 
 /*
@@ -827,7 +838,7 @@ static funcentry_T global_functions[] =
     {"remote_read",    1, 2, FEARG_1,    ret_string,   f_remote_read},
     {"remote_send",    2, 3, FEARG_1,    ret_string,   f_remote_send},
     {"remote_startserver", 1, 1, FEARG_1, ret_void,    f_remote_startserver},
-    {"remove",         2, 3, FEARG_1,    ret_any,      f_remove},
+    {"remove",         2, 3, FEARG_1,    ret_remove,   f_remove},
     {"rename",         2, 2, FEARG_1,    ret_number,   f_rename},
     {"repeat",         2, 2, FEARG_1,    ret_first_arg, f_repeat},
     {"resolve",                1, 1, FEARG_1,    ret_string,   f_resolve},
index 65b525706a7478bfed4241c0d9a9a966a75dbf96..347dc819e0e0c73bef69acc1e00189eff4f675f5 100644 (file)
@@ -927,6 +927,15 @@ def Test_insert_return_type()
   assert_equal(6, res)
 enddef
 
+def Test_remove_return_type()
+  let l = remove(#{one: [1, 2], two: [3, 4]}, 'one')
+  let res = 0
+  for n in l
+    res += n
+  endfor
+  assert_equal(3, res)
+enddef
+
 def Test_filter_return_type()
   let l = filter([1, 2, 3], {-> 1})
   let res = 0
index 6d4d6e93bb1503f60e0a27ef286a602235388de6..65cf985a2fa5fca49ab44062c6912ce1d99f4611 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1143,
 /**/
     1142,
 /**/