]> granicus.if.org Git - vim/commitdiff
patch 8.2.4927: return type of remove() incorrect when using three arguments v8.2.4927
authorBram Moolenaar <Bram@vim.org>
Mon, 9 May 2022 13:12:14 +0000 (14:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 9 May 2022 13:12:14 +0000 (14:12 +0100)
Problem:    Return type of remove() incorrect when using three arguments.
Solution:   Use first argument type when there are three arguments.
            (closes #10387)

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

index efade6cab66dc0dfa63ce20be1bddad67931a2b1..f7a04fdc9823155f508dc46fdd46e3e2af029c3d 100644 (file)
@@ -1420,13 +1420,18 @@ ret_argv(int argcount,
     static type_T *
 ret_remove(int argcount,
        type2_T *argtypes,
-       type_T  **decl_type UNUSED)
+       type_T  **decl_type)
 {
     if (argcount > 0)
     {
        if (argtypes[0].type_curr->tt_type == VAR_LIST
                || argtypes[0].type_curr->tt_type == VAR_DICT)
        {
+           if (argcount == 3)
+           {
+               *decl_type = argtypes[0].type_decl;
+               return argtypes[0].type_curr;
+           }
            if (argtypes[0].type_curr->tt_type
                                             == argtypes[0].type_decl->tt_type)
                *decl_type = argtypes[0].type_decl->tt_member;
index c9334bc0f57db4a41f6a6c4db0324632038c6ae5..2c4e9ae99cb17181d7cbc76657aa016acbc86c31 100644 (file)
@@ -3208,12 +3208,11 @@ def Test_remove()
 enddef
 
 def Test_remove_return_type()
-  var l = remove({one: [1, 2], two: [3, 4]}, 'one')
-  var res = 0
-  for n in l
-    res += n
-  endfor
-  res->assert_equal(3)
+  var l: list<number> = remove({one: [1, 2], two: [3, 4]}, 'one')
+  l->assert_equal([1, 2])
+
+  var ll: list<number> = remove(range(3), 0, 1)
+  ll->assert_equal([0, 1])
 enddef
 
 def Test_rename()
index c23757fe2334a5a941a77cfdde7a8a25390f96bb..54eb6521b89985924cad5905c34a16cb5d0317ac 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4927,
 /**/
     4926,
 /**/