Patch 8.2.0570
Problem:    Vim9: no error when omitting type from argument.
Solution:   Enforce specifying argument types.
Files:      src/userfunc.c, src/ex_eval.c, src/testdir/test_vim9_script.vim,
            src/testdir/test_vim9_func.vim, src/testdir/test_vim9_expr.vim
            src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.0569/src/userfunc.c      2020-04-13 14:41:31.667954106 +0200
--- src/userfunc.c      2020-04-13 16:49:24.738322434 +0200
***************
*** 64,77 ****
  }
  
  /*
!  * Get one function argument and an optional type: "arg: type".
   * Return a pointer to after the type.
   * When something is wrong return "arg".
   */
      static char_u *
  one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
  {
!     char_u *p = arg;
  
      while (ASCII_ISALNUM(*p) || *p == '_')
        ++p;
--- 64,79 ----
  }
  
  /*
!  * Get one function argument.
!  * If "argtypes" is not NULL also get the type: "arg: type".
   * Return a pointer to after the type.
   * When something is wrong return "arg".
   */
      static char_u *
  one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
  {
!     char_u    *p = arg;
!     char_u    *arg_copy = NULL;
  
      while (ASCII_ISALNUM(*p) || *p == '_')
        ++p;
***************
*** 87,93 ****
        return arg;
      if (newargs != NULL)
      {
-       char_u  *arg_copy;
        int     c;
        int     i;
  
--- 89,94 ----
***************
*** 119,132 ****
      {
        char_u *type = NULL;
  
        if (*p == ':')
        {
            type = skipwhite(p + 1);
            p = skip_type(type);
            type = vim_strnsave(type, p - type);
        }
!       else if (*skipwhite(p) == ':')
!           emsg(_("E1059: No white space allowed before :"));
        ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type;
      }
  
--- 120,143 ----
      {
        char_u *type = NULL;
  
+       if (VIM_ISWHITE(*p) && *skipwhite(p) == ':')
+       {
+           semsg(_("E1059: No white space allowed before colon: %s"),
+                                           arg_copy == NULL ? arg : arg_copy);
+           p = skipwhite(p);
+       }
        if (*p == ':')
        {
            type = skipwhite(p + 1);
            p = skip_type(type);
            type = vim_strnsave(type, p - type);
        }
!       else if (*skipwhite(p) != '=')
!       {
!           semsg(_("E1077: Missing argument type for %s"),
!                                           arg_copy == NULL ? arg : arg_copy);
!           return arg;
!       }
        ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type;
      }
  
*** ../vim-8.2.0569/src/ex_eval.c       2020-04-02 21:13:21.392362410 +0200
--- src/ex_eval.c       2020-04-13 16:53:25.545786441 +0200
***************
*** 2273,2281 ****
   * ":endfunction" when not after a ":function"
   */
      void
! ex_endfunction(exarg_T *eap UNUSED)
  {
!     emsg(_("E193: :endfunction not inside a function"));
  }
  
  /*
--- 2273,2284 ----
   * ":endfunction" when not after a ":function"
   */
      void
! ex_endfunction(exarg_T *eap)
  {
!     if (eap->cmdidx == CMD_enddef)
!       emsg(_("E193: :enddef not inside a function"));
!     else
!       emsg(_("E193: :endfunction not inside a function"));
  }
  
  /*
*** ../vim-8.2.0569/src/testdir/test_vim9_script.vim    2020-04-13 
14:41:31.671954102 +0200
--- src/testdir/test_vim9_script.vim    2020-04-13 16:55:54.097456309 +0200
***************
*** 917,923 ****
    CheckDefFailure(['for # in range(5)'], 'E690:')
    CheckDefFailure(['for i In range(5)'], 'E690:')
    CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:')
!   CheckScriptFailure(['def Func(arg)', 'for arg in range(5)', 'enddef'], 
'E1006:')
    CheckDefFailure(['for i in "text"'], 'E1024:')
    CheckDefFailure(['for i in xxx'], 'E1001:')
    CheckDefFailure(['endfor'], 'E588:')
--- 917,923 ----
    CheckDefFailure(['for # in range(5)'], 'E690:')
    CheckDefFailure(['for i In range(5)'], 'E690:')
    CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:')
!   CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef'], 
'E1006:')
    CheckDefFailure(['for i in "text"'], 'E1024:')
    CheckDefFailure(['for i in xxx'], 'E1001:')
    CheckDefFailure(['endfor'], 'E588:')
*** ../vim-8.2.0569/src/testdir/test_vim9_func.vim      2020-04-13 
14:41:31.671954102 +0200
--- src/testdir/test_vim9_func.vim      2020-04-13 16:55:04.205567128 +0200
***************
*** 250,255 ****
--- 250,256 ----
  def Test_arg_type_wrong()
    CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 
'E1008: Missing <type>')
    CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: 
Missing name after ...')
+   CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
  enddef
  
  def Test_vim9script_call()
*** ../vim-8.2.0569/src/testdir/test_vim9_expr.vim      2020-04-12 
20:55:16.998819659 +0200
--- src/testdir/test_vim9_expr.vim      2020-04-13 16:50:02.206239331 +0200
***************
*** 859,869 ****
    assert_equal(88, --nr)
  enddef
  
! def Echo(arg): string
    return arg
  enddef
  
! def s:EchoArg(arg): string
    return arg
  enddef
  
--- 859,869 ----
    assert_equal(88, --nr)
  enddef
  
! def Echo(arg: any): string
    return arg
  enddef
  
! def s:EchoArg(arg: any): string
    return arg
  enddef
  
***************
*** 991,996 ****
--- 991,997 ----
    assert_equal(123, d.key)
  enddef
  
+ 
  func Test_expr7_trailing_fails()
    call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107')
    call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)} ()'], 'E274')
*** ../vim-8.2.0569/src/testdir/test_vim9_disassemble.vim       2020-04-12 
22:53:50.767656185 +0200
--- src/testdir/test_vim9_disassemble.vim       2020-04-13 16:36:03.452065125 
+0200
***************
*** 160,166 ****
          res)
  enddef
  
! def FuncWithArg(arg)
    echo arg
  enddef
  
--- 160,166 ----
          res)
  enddef
  
! def FuncWithArg(arg: any)
    echo arg
  enddef
  
***************
*** 432,438 ****
          instr)
  enddef
  
! def AndOr(arg): string
    if arg == 1 && arg != 2 || arg == 4
      return 'yes'
    endif
--- 432,438 ----
          instr)
  enddef
  
! def AndOr(arg: any): string
    if arg == 1 && arg != 2 || arg == 4
      return 'yes'
    endif
*** ../vim-8.2.0569/src/version.c       2020-04-13 15:06:49.917355649 +0200
--- src/version.c       2020-04-13 16:22:59.373677291 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     570,
  /**/

-- 
"I've been teaching myself to play the piano for about 5 years and now write
most of my songs on it, mainly because I can never find any paper."
                Jeff Lynne, ELO's greatest hits

 /// 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/202004131521.03DFLSeV004691%40masaka.moolenaar.net.

Raspunde prin e-mail lui