]> granicus.if.org Git - vim/commitdiff
patch 8.2.3317: Vim9: No error for missing white space before return type v8.2.3317
authorBram Moolenaar <Bram@vim.org>
Sun, 8 Aug 2021 17:07:37 +0000 (19:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 8 Aug 2021 17:07:37 +0000 (19:07 +0200)
Problem:    Vim9: No error for missing white space before return type.
Solution:   Check for white space. (closes #8733)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index 5704511df702f1bf161c34f7bf32ccc3c676a819..de7b980fde946ef837a685e02c980a3e82ba26c4 100644 (file)
@@ -1429,6 +1429,27 @@ def Test_return_type_wrong()
         'defcompile'], 'E1003:')
   delfunc! g:Func
 
+  CheckScriptFailure([
+        'def Func():number',
+        'return 123',
+        'enddef',
+        'defcompile'], 'E1069:')
+  delfunc! g:Func
+
+  CheckScriptFailure([
+        'def Func() :number',
+        'return 123',
+        'enddef',
+        'defcompile'], 'E1059:')
+  delfunc! g:Func
+
+  CheckScriptFailure([
+        'def Func() : number',
+        'return 123',
+        'enddef',
+        'defcompile'], 'E1059:')
+  delfunc! g:Func
+
   CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
   delfunc! g:Func
   CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
index 79a6621b249527e9814ddd92158498b538072368..7a7617f5eb7422fe8bb81f6edfbce6a01828dfe9 100644 (file)
@@ -4066,8 +4066,15 @@ define_function(exarg_T *eap, char_u *name_arg)
     if (eap->cmdidx == CMD_def)
     {
        // find the return type: :def Func(): type
-       if (*p == ':')
+       if (*skipwhite(p) == ':')
        {
+           if (*p != ':')
+           {
+               semsg(_(e_no_white_space_allowed_before_colon_str), p);
+               p = skipwhite(p);
+           }
+           else if (!IS_WHITE_OR_NUL(p[1]))
+               semsg(_(e_white_space_required_after_str_str), ":", p);
            ret_type = skipwhite(p + 1);
            p = skip_type(ret_type, FALSE);
            if (p > ret_type)
index 3e209fe272a926360576448592ffd63aecf0bf2c..aacefc03d795b99f9e59f75bdc2a8d21c8abb457 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3317,
 /**/
     3316,
 /**/