Patch 8.2.3269
Problem:    Vim9: wrong argument check for partial. (Naohiro Ono)
Solution:   Handle getting return type without arguments. Correct the minimal
            number of arguments for what is included in the partial.
            (closes #8667)
Files:      src/evalfunc.c, src/vim9type.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.3268/src/evalfunc.c      2021-07-31 22:03:54.508104860 +0200
--- src/evalfunc.c      2021-08-01 15:19:39.071214122 +0200
***************
*** 932,953 ****
      return &t_void;
  }
      static type_T *
! ret_repeat(int argcount UNUSED, type_T **argtypes)
  {
      if (argtypes[0] == &t_number)
        return &t_string;
      return argtypes[0];
  }
  // for map(): returns first argument but item type may differ
      static type_T *
! ret_first_cont(int argcount UNUSED, type_T **argtypes)
  {
!     if (argtypes[0]->tt_type == VAR_LIST)
!       return &t_list_any;
!     if (argtypes[0]->tt_type == VAR_DICT)
!       return &t_dict_any;
!     if (argtypes[0]->tt_type == VAR_BLOB)
!       return argtypes[0];
      return &t_any;
  }
  
--- 932,958 ----
      return &t_void;
  }
      static type_T *
! ret_repeat(int argcount, type_T **argtypes)
  {
+     if (argcount == 0)
+       return &t_any;
      if (argtypes[0] == &t_number)
        return &t_string;
      return argtypes[0];
  }
  // for map(): returns first argument but item type may differ
      static type_T *
! ret_first_cont(int argcount, type_T **argtypes)
  {
!     if (argcount > 0)
!     {
!       if (argtypes[0]->tt_type == VAR_LIST)
!           return &t_list_any;
!       if (argtypes[0]->tt_type == VAR_DICT)
!           return &t_dict_any;
!       if (argtypes[0]->tt_type == VAR_BLOB)
!           return argtypes[0];
!     }
      return &t_any;
  }
  
***************
*** 987,995 ****
  }
  
      static type_T *
! ret_remove(int argcount UNUSED, type_T **argtypes)
  {
!     if (argtypes != NULL)
      {
        if (argtypes[0]->tt_type == VAR_LIST
                || argtypes[0]->tt_type == VAR_DICT)
--- 992,1000 ----
  }
  
      static type_T *
! ret_remove(int argcount, type_T **argtypes)
  {
!     if (argcount > 0)
      {
        if (argtypes[0]->tt_type == VAR_LIST
                || argtypes[0]->tt_type == VAR_DICT)
***************
*** 2446,2451 ****
--- 2451,2457 ----
   * Call the "f_retfunc" function to obtain the return type of function "idx".
   * "argtypes" is the list of argument types or NULL when there are no
   * arguments.
+  * "argcount" may be less than the actual count when only getting the type.
   */
      type_T *
  internal_func_ret_type(int idx, int argcount, type_T **argtypes)
*** ../vim-8.2.3268/src/vim9type.c      2021-07-29 22:48:50.103129907 +0200
--- src/vim9type.c      2021-08-01 15:38:39.916473586 +0200
***************
*** 378,383 ****
--- 378,388 ----
      type->tt_type = tv->v_type;
      type->tt_argcount = argcount;
      type->tt_min_argcount = min_argcount;
+     if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial->pt_argc > 0)
+     {
+       type->tt_argcount -= tv->vval.v_partial->pt_argc;
+       type->tt_min_argcount -= tv->vval.v_partial->pt_argc;
+     }
      type->tt_member = member_type;
  
      return type;
*** ../vim-8.2.3268/src/testdir/test_vim9_func.vim      2021-07-25 
18:06:44.155292431 +0200
--- src/testdir/test_vim9_func.vim      2021-08-01 15:37:51.808584725 +0200
***************
*** 2582,2605 ****
  enddef
  
  def Test_partial_call()
!   var Xsetlist = function('setloclist', [0])
!   Xsetlist([], ' ', {title: 'test'})
!   getloclist(0, {title: 1})->assert_equal({title: 'test'})
! 
!   Xsetlist = function('setloclist', [0, [], ' '])
!   Xsetlist({title: 'test'})
!   getloclist(0, {title: 1})->assert_equal({title: 'test'})
! 
!   Xsetlist = function('setqflist')
!   Xsetlist([], ' ', {title: 'test'})
!   getqflist({title: 1})->assert_equal({title: 'test'})
! 
!   Xsetlist = function('setqflist', [[], ' '])
!   Xsetlist({title: 'test'})
!   getqflist({title: 1})->assert_equal({title: 'test'})
! 
!   var Len: func: number = function('len', ['word'])
!   assert_equal(4, Len())
  enddef
  
  def Test_cmd_modifier()
--- 2582,2612 ----
  enddef
  
  def Test_partial_call()
!   var lines =<< trim END
!       var Xsetlist: func
!       Xsetlist = function('setloclist', [0])
!       Xsetlist([], ' ', {title: 'test'})
!       getloclist(0, {title: 1})->assert_equal({title: 'test'})
! 
!       Xsetlist = function('setloclist', [0, [], ' '])
!       Xsetlist({title: 'test'})
!       getloclist(0, {title: 1})->assert_equal({title: 'test'})
! 
!       Xsetlist = function('setqflist')
!       Xsetlist([], ' ', {title: 'test'})
!       getqflist({title: 1})->assert_equal({title: 'test'})
! 
!       Xsetlist = function('setqflist', [[], ' '])
!       Xsetlist({title: 'test'})
!       getqflist({title: 1})->assert_equal({title: 'test'})
! 
!       var Len: func: number = function('len', ['word'])
!       assert_equal(4, Len())
! 
!       var RepeatFunc = function('repeat', ['o'])
!       assert_equal('ooooo', RepeatFunc(5))
!   END
!   CheckDefAndScriptSuccess(lines)
  enddef
  
  def Test_cmd_modifier()
*** ../vim-8.2.3268/src/version.c       2021-08-01 14:52:05.558645405 +0200
--- src/version.c       2021-08-01 15:40:01.608285606 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3269,
  /**/

-- 
Back up my hard drive?  I can't find the reverse switch!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/202108011341.171DfckF258649%40masaka.moolenaar.net.

Raspunde prin e-mail lui