]> granicus.if.org Git - vim/commitdiff
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work v8.2.2575
authorBram Moolenaar <Bram@vim.org>
Sat, 6 Mar 2021 20:01:09 +0000 (21:01 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 6 Mar 2021 20:01:09 +0000 (21:01 +0100)
Problem:    Vim9: a function name with "->" in the next line doesn't work.
Solution:   Recognize a function name by itself. (closes #7770)

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

index f638c84b06e0b997349e6f01cde2563138376e66..dd6e966de1766b6c8bdf29aee1e43bfd71fd1af4 100644 (file)
@@ -355,6 +355,25 @@ def Test_method_call_linebreak()
   END
   CheckDefAndScriptSuccess(lines)
 
+  lines =<< trim END
+      new
+      def Foo(): string
+        return 'the text'
+      enddef
+      def Bar(F: func): string
+        return F()
+      enddef
+      def Test()
+        Foo
+          ->Bar()
+          ->setline(1)
+      enddef
+      Test()
+      assert_equal('the text', getline(1))
+      bwipe!
+  END
+  CheckDefAndScriptSuccess(lines)
+
   lines =<< trim END
       new
       g:shortlist
index 278f77bc690007d4fc4c562e75fc93a6aed154f9..48f3faae15d4e0c8ab0981ee925602c56cef95af 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2575,
 /**/
     2574,
 /**/
index f6d1fb3d8b1598d83b1fdfed833a96a3c3c71048..c7810602373c098a4177631a73b91c1d26d4f21a 100644 (file)
@@ -386,6 +386,26 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
            || find_imported(name, len, cctx) != NULL;
 }
 
+/*
+ * Return TRUE if "name" is a local variable, argument, script variable,
+ * imported or function.
+ */
+    static int
+item_exists(char_u *name, size_t len, cctx_T *cctx)
+{
+    int            is_global;
+
+    if (variable_exists(name, len, cctx))
+       return TRUE;
+
+    // Find a function, so that a following "->" works.  Skip "g:" before a
+    // function name.
+    // Do not check for an internal function, since it might also be a
+    // valid command, such as ":split" versuse "split()".
+    is_global = (name[0] == 'g' && name[1] == ':');
+    return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
+}
+
 /*
  * Check if "p[len]" is already defined, either in script "import_sid" or in
  * compilation context "cctx".  "cctx" is NULL at the script level.
@@ -728,7 +748,7 @@ get_compare_isn(exprtype_T exprtype, vartype_T type1, vartype_T type2)
     }
     else if (type1 == VAR_ANY || type2 == VAR_ANY
            || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT)
-             && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT)))
+             && (type2 == VAR_NUMBER || type2 == VAR_FLOAT)))
        isntype = ISN_COMPAREANY;
 
     if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT)
@@ -8399,8 +8419,7 @@ compile_def_function(
            }
        }
        p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
-                  : (int (*)(char_u *, size_t, cctx_T *))variable_exists,
-                                                                       &cctx);
+                   : (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx);
 
        if (p == NULL)
        {