Patch 8.2.0548
Problem:    Vim9: not all possible func type errors tested.
Solution:   Add more tests.
Files:      src/vim9compile.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.0547/src/vim9compile.c   2020-04-11 22:31:24.054346877 +0200
--- src/vim9compile.c   2020-04-11 23:16:12.139322539 +0200
***************
*** 1648,1654 ****
--- 1648,1657 ----
                        {
                            ++p;
                            if (!VIM_ISWHITE(*p))
+                           {
                                semsg(_(e_white_after), ",");
+                               return &t_any;
+                           }
                        }
                        p = skipwhite(p);
                        if (argcount == MAX_FUNC_ARGS)
***************
*** 1675,1681 ****
                    *arg = skipwhite(*arg);
                    ret_type = parse_type(arg, type_gap);
                }
!               if (flags == 0 && first_optional == -1)
                    type = get_func_type(ret_type, argcount, type_gap);
                else
                {
--- 1678,1684 ----
                    *arg = skipwhite(*arg);
                    ret_type = parse_type(arg, type_gap);
                }
!               if (flags == 0 && first_optional == -1 && argcount <= 0)
                    type = get_func_type(ret_type, argcount, type_gap);
                else
                {
***************
*** 1822,1829 ****
        case VAR_CHANNEL: return "channel";
        case VAR_LIST: return "list";
        case VAR_DICT: return "dict";
!       case VAR_FUNC: return "func";
!       case VAR_PARTIAL: return "partial";
      }
      return "unknown";
  }
--- 1825,1833 ----
        case VAR_CHANNEL: return "channel";
        case VAR_LIST: return "list";
        case VAR_DICT: return "dict";
! 
!       case VAR_FUNC:
!       case VAR_PARTIAL: return "func";
      }
      return "unknown";
  }
***************
*** 1853,1859 ****
            return *tofree;
        }
      }
!     if (type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
      {
        garray_T    ga;
        int         i;
--- 1857,1863 ----
            return *tofree;
        }
      }
!     if (type->tt_type == VAR_FUNC)
      {
        garray_T    ga;
        int         i;
***************
*** 1866,1877 ****
        STRCPY(ga.ga_data, "func(");
        ga.ga_len += 5;
  
!       for (i = 0; i < type->tt_argcount + varargs; ++i)
        {
            char *arg_free;
!           char *arg_type = type_name(type->tt_args[i], &arg_free);
            int  len;
  
            if (i > 0)
            {
                STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
--- 1870,1885 ----
        STRCPY(ga.ga_data, "func(");
        ga.ga_len += 5;
  
!       for (i = 0; i < type->tt_argcount; ++i)
        {
            char *arg_free;
!           char *arg_type;
            int  len;
  
+           if (type->tt_args == NULL)
+               arg_type = "[unknown]";
+           else
+               arg_type = type_name(type->tt_args[i], &arg_free);
            if (i > 0)
            {
                STRCPY((char *)ga.ga_data + ga.ga_len, ", ");
***************
*** 1884,1890 ****
                return "[unknown]";
            }
            *tofree = ga.ga_data;
!           if (i == type->tt_argcount)
            {
                STRCPY((char *)ga.ga_data + ga.ga_len, "...");
                ga.ga_len += 3;
--- 1892,1898 ----
                return "[unknown]";
            }
            *tofree = ga.ga_data;
!           if (varargs && i == type->tt_argcount - 1)
            {
                STRCPY((char *)ga.ga_data + ga.ga_len, "...");
                ga.ga_len += 3;
***************
*** 4007,4014 ****
        }
  
        // new local variable
!       if ((type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
!                                           && var_check_func_name(name, TRUE))
            goto theend;
        idx = reserve_local(cctx, arg, varlen, cmdidx == CMD_const, type);
        if (idx < 0)
--- 4015,4021 ----
        }
  
        // new local variable
!       if (type->tt_type == VAR_FUNC && var_check_func_name(name, TRUE))
            goto theend;
        idx = reserve_local(cctx, arg, varlen, cmdidx == CMD_const, type);
        if (idx < 0)
*** ../vim-8.2.0547/src/testdir/test_vim9_func.vim      2020-04-11 
20:50:25.376120463 +0200
--- src/testdir/test_vim9_func.vim      2020-04-11 23:11:48.167961249 +0200
***************
*** 442,447 ****
--- 442,451 ----
    return arg
  enddef
  
+ def FuncTwoArgNoRet(one: bool, two: number)
+   funcResult = two
+ enddef
+ 
  def FuncOneArgRetString(arg: string): string
    return arg
  enddef
***************
*** 511,516 ****
--- 515,528 ----
    CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1013: 
type mismatch, expected func() but got func(): number')
    CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1013: 
type mismatch, expected func() but got func(number)')
    CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: 
type mismatch, expected func() but got func(number): number')
+   CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1013: 
type mismatch, expected func(bool) but got func(bool, number)')
+   CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 
'E1013: type mismatch, expected func(?bool) but got func(bool, number)')
+   CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 
'E1013: type mismatch, expected func(...bool) but got func(bool, number)')
+ 
+   call CheckDefFailure(['let RefWrong: func(string ,number)'], 'E1068:')
+   call CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:')
+   call CheckDefFailure(['let RefWrong: func(bool, bool, bool, bool, bool, 
bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, 
bool, bool)'], 'E740:')
+   call CheckDefFailure(['let RefWrong: func(bool):string'], 'E1069:')
  enddef
  
  def Test_func_return_type()
*** ../vim-8.2.0547/src/version.c       2020-04-11 22:38:31.501379060 +0200
--- src/version.c       2020-04-11 22:47:47.559805261 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     548,
  /**/

-- 
Corn oil comes from corn and olive oil comes from olives, so where
does baby oil come from?

 /// 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/202004112117.03BLHgHO020875%40masaka.moolenaar.net.

Raspunde prin e-mail lui