]> granicus.if.org Git - vim/commitdiff
patch 8.2.1270: Vim9: not skipping over function type declaration v8.2.1270
authorBram Moolenaar <Bram@vim.org>
Wed, 22 Jul 2020 17:30:06 +0000 (19:30 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 22 Jul 2020 17:30:06 +0000 (19:30 +0200)
Problem:    Vim9: not skipping over function type declaration with only a
            return type.
Solution:   Skip over the return type. (issue #6507)

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

index 6d83ddc515d4fe6854c5f3860f491282a635d11d..3fa5d6abea4d30817eaadbbaa017e7011793cf14 100644 (file)
@@ -260,6 +260,16 @@ def Test_call_funcref()
   assert_equal(3, g:SomeFunc('abc'))
   assert_fails('NotAFunc()', 'E117:')
   assert_fails('g:NotAFunc()', 'E117:')
+
+  let lines =<< trim END
+    vim9script
+    def RetNumber(): number
+      return 123
+    enddef
+    let Funcref: func: number = function('RetNumber')
+    assert_equal(123, Funcref())
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 let SomeFunc = function('len')
index cf64327208790db272e7ab89bc94abebb98bdaf0..9ac0340a300cdaa9fc2d335117b7fd5dabaec2a4 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1270,
 /**/
     1269,
 /**/
index 0e3e01ac73a03b019ead429816f04238be3b602d..55f08a73ea83e47a8429512b5317fde49aaad418 100644 (file)
@@ -1881,26 +1881,35 @@ skip_type(char_u *start)
        if (*p == '>')
            ++p;
     }
-    else if (*p == '(' && STRNCMP("func", start, 4) == 0)
+    else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1])))
+                                            && STRNCMP("func", start, 4) == 0)
     {
-       // handle func(args): type
-       ++p;
-       while (*p != ')' && *p != NUL)
+       if (*p == '(')
        {
-           char_u *sp = p;
+           // handle func(args): type
+           ++p;
+           while (*p != ')' && *p != NUL)
+           {
+               char_u *sp = p;
 
-           p = skip_type(p);
-           if (p == sp)
-               return p;  // syntax error
-           if (*p == ',')
-               p = skipwhite(p + 1);
+               p = skip_type(p);
+               if (p == sp)
+                   return p;  // syntax error
+               if (*p == ',')
+                   p = skipwhite(p + 1);
+           }
+           if (*p == ')')
+           {
+               if (p[1] == ':')
+                   p = skip_type(skipwhite(p + 2));
+               else
+                   p = skipwhite(p + 1);
+           }
        }
-       if (*p == ')')
+       else
        {
-           if (p[1] == ':')
-               p = skip_type(skipwhite(p + 2));
-           else
-               p = skipwhite(p + 1);
+           // handle func: return_type
+           p = skip_type(skipwhite(p + 1));
        }
     }