]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1081: using "->" with split lines does not always work v9.0.1081
authorBram Moolenaar <Bram@vim.org>
Mon, 19 Dec 2022 20:28:38 +0000 (20:28 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 19 Dec 2022 20:28:38 +0000 (20:28 +0000)
Problem:    Using "->" with split lines does not always work.
Solution:   Avoid trying to get another line. (closes #11723)

src/eval.c
src/testdir/test_user_func.vim
src/version.c

index 934d6402690f8344390018757f58127b6fde7ba0..94bb4e3770a8e2c2573aed3655c0568078b2536d 100644 (file)
@@ -4548,11 +4548,19 @@ eval_method(
        if (**arg != '(' && alias == NULL
                                    && (paren = vim_strchr(*arg, '(')) != NULL)
        {
-           char_u *deref;
-
            *arg = name;
+
+           // Truncate the name a the "(".  Avoid trying to get another line
+           // by making "getline" NULL.
            *paren = NUL;
-           deref = deref_function_name(arg, &tofree, evalarg, verbose);
+           char_u      *(*getline)(int, void *, int, getline_opt_T) = NULL;
+           if (evalarg != NULL)
+           {
+               getline = evalarg->eval_getline;
+               evalarg->eval_getline = NULL;
+           }
+
+           char_u *deref = deref_function_name(arg, &tofree, evalarg, verbose);
            if (deref == NULL)
            {
                *arg = name + len;
@@ -4563,7 +4571,10 @@ eval_method(
                name = deref;
                len = (long)STRLEN(name);
            }
+
            *paren = '(';
+           if (getline != NULL)
+               evalarg->eval_getline = getline;
        }
 
        if (ret == OK)
index 79afea1e0e409ffd51af5e4986e913644fb5f3dc..ade259cffaa4223235b6bb6f73b2599c345f5305 100644 (file)
@@ -179,6 +179,60 @@ func Test_user_method()
   eval 'bar'->s:addFoo()->assert_equal('barfoo')
 endfunc
 
+func Test_method_with_linebreaks()
+  let lines =<< trim END
+      vim9script
+
+      export def Scan(ll: list<number>): func(func(number))
+        return (Emit: func(number)) => {
+          for v in ll
+            Emit(v)
+          endfor
+        }
+      enddef
+
+      export def Build(Cont: func(func(number))): list<number>
+        var result: list<number> = []
+        Cont((v) => {
+            add(result, v)
+        })
+        return result
+      enddef
+
+      export def Noop(Cont: func(func(number))): func(func(number))
+        return (Emit: func(number)) => {
+          Cont(Emit)
+        }
+      enddef
+  END
+  call writefile(lines, 'Xlib.vim', 'D')
+
+  let lines =<< trim END
+      vim9script
+
+      import "./Xlib.vim" as lib
+
+      const x = [1, 2, 3]
+
+      var result = lib.Scan(x)->lib.Noop()->lib.Build()
+      assert_equal([1, 2, 3], result)
+
+      result = lib.Scan(x)->lib.Noop()
+              ->lib.Build()
+      assert_equal([1, 2, 3], result)
+
+      result = lib.Scan(x)
+            ->lib.Noop()->lib.Build()
+      assert_equal([1, 2, 3], result)
+
+      result = lib.Scan(x)
+                ->lib.Noop()
+                ->lib.Build()
+      assert_equal([1, 2, 3], result)
+  END
+  call v9.CheckScriptSuccess(lines)
+endfunc
+
 func Test_failed_call_in_try()
   try | call UnknownFunc() | catch | endtry
 endfunc
index a2371286c9e97102fbeecbaca9a75704de32401a..90522fdd20db6963d3d79ce9e7b9fec450a302b0 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1081,
 /**/
     1080,
 /**/