Patch 8.2.1143
Problem:    Vim9: return type of remove() is any.
Solution:   Use the member type of the first argument, if known.
Files:      src/evalfunc.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1142/src/evalfunc.c      2020-07-05 20:47:14.903238755 +0200
--- src/evalfunc.c      2020-07-05 20:53:53.273519731 +0200
***************
*** 382,387 ****
--- 382,398 ----
      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,833 ****
      {"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},
      {"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},
--- 838,844 ----
      {"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_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},
*** ../vim-8.2.1142/src/testdir/test_vim9_func.vim      2020-07-05 
20:47:14.903238755 +0200
--- src/testdir/test_vim9_func.vim      2020-07-05 20:51:39.398079895 +0200
***************
*** 927,932 ****
--- 927,941 ----
    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
*** ../vim-8.2.1142/src/version.c       2020-07-05 20:47:14.903238755 +0200
--- src/version.c       2020-07-05 20:54:37.661336943 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1143,
  /**/

-- 
The acknowledged parents of reengineering are Michael Hammer and James Champy.
When I say they're the "parents" I don't mean they had sex - and I apologize
for making you think about it.  I mean they wrote the best-selling business
book _Reengineering the Corporation_, which was published in 1993.
   Businesses flocked to reengineering like frat boys to a drunken
cheerleader.  (This analogy wasn't necessary, but I'm trying to get my mind
off that Hammer and Champy thing.)
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202007051856.065Iu3qV649432%40masaka.moolenaar.net.

Raspunde prin e-mail lui