]> granicus.if.org Git - vim/commitdiff
patch 8.2.0570: Vim9: no error when omitting type from argument v8.2.0570
authorBram Moolenaar <Bram@vim.org>
Mon, 13 Apr 2020 15:21:00 +0000 (17:21 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 13 Apr 2020 15:21:00 +0000 (17:21 +0200)
Problem:    Vim9: no error when omitting type from argument.
Solution:   Enforce specifying argument types.

src/ex_eval.c
src/testdir/test_vim9_disassemble.vim
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_func.vim
src/testdir/test_vim9_script.vim
src/userfunc.c
src/version.c

index 72da2f252d4da04ebda5ec76031905667ff154f9..7ffc145ae43a84db40d4e6056a92dad1fc049fee 100644 (file)
@@ -2273,9 +2273,12 @@ rewind_conditionals(
  * ":endfunction" when not after a ":function"
  */
     void
-ex_endfunction(exarg_T *eap UNUSED)
+ex_endfunction(exarg_T *eap)
 {
-    emsg(_("E193: :endfunction not inside a function"));
+    if (eap->cmdidx == CMD_enddef)
+       emsg(_("E193: :enddef not inside a function"));
+    else
+       emsg(_("E193: :endfunction not inside a function"));
 }
 
 /*
index bfbb4729b30d65baf992c3aca52655f45118db38..f6de6858e1b68a2f073593f08bf433194b66717a 100644 (file)
@@ -160,7 +160,7 @@ def Test_disassemble_new()
         res)
 enddef
 
-def FuncWithArg(arg)
+def FuncWithArg(arg: any)
   echo arg
 enddef
 
@@ -432,7 +432,7 @@ def Test_disassemble_lambda()
         instr)
 enddef
 
-def AndOr(arg): string
+def AndOr(arg: any): string
   if arg == 1 && arg != 2 || arg == 4
     return 'yes'
   endif
index 062502fe2bc7950c7b97923c3cb445dec8daceec..dad4dee7d8d2b5246d0963663409ba876b66e7bc 100644 (file)
@@ -859,11 +859,11 @@ def Test_expr7_negate()
   assert_equal(88, --nr)
 enddef
 
-def Echo(arg): string
+def Echo(arg: any): string
   return arg
 enddef
 
-def s:EchoArg(arg): string
+def s:EchoArg(arg: any): string
   return arg
 enddef
 
@@ -991,6 +991,7 @@ def Test_expr7_trailing()
   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')
index f0b0ad063c7b257933a18d6da43aa099e3c0c877..8a6c3d607ae5e6c2929e21e0edc07ea1fc46f649 100644 (file)
@@ -250,6 +250,7 @@ enddef
 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()
index c3e3f22623aa049523ac6319efcbb7403652483a..9c6e5c047bc05261a59134b826f4312e6ed947a2 100644 (file)
@@ -917,7 +917,7 @@ def Test_for_loop_fails()
   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:')
+  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:')
index 95483e2b367666d147548dd0cda3f3c4920efde5..6ca89806861c9db69497532a59236bbbefe53caa 100644 (file)
@@ -64,14 +64,16 @@ func_tbl_get(void)
 }
 
 /*
- * Get one function argument and an optional type: "arg: type".
+ * 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     *p = arg;
+    char_u     *arg_copy = NULL;
 
     while (ASCII_ISALNUM(*p) || *p == '_')
        ++p;
@@ -87,7 +89,6 @@ one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
        return arg;
     if (newargs != NULL)
     {
-       char_u  *arg_copy;
        int     c;
        int     i;
 
@@ -119,14 +120,24 @@ one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
     {
        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) == ':')
-           emsg(_("E1059: No white space allowed before :"));
+       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;
     }
 
index d447b7aed4f486e517aedaa425a924510d18a1db..df1dcec7a1d8d5ae0ed0e0288ff1c4af68ed4576 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    570,
 /**/
     569,
 /**/