]> granicus.if.org Git - vim/commitdiff
patch 9.0.1239: cannot have a line break before an object member access v9.0.1239
authorBram Moolenaar <Bram@vim.org>
Tue, 24 Jan 2023 13:03:37 +0000 (13:03 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 24 Jan 2023 13:03:37 +0000 (13:03 +0000)
Problem:    Cannot have a line break before an object member access.
Solution:   Check for "." in next line. (closes #11864)

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

index 2a8b1c52ee5082caa0573e08674837eac86a3cac..699f43baceda2ac421d6c2bb280938e58e53adcb 100644 (file)
@@ -6747,7 +6747,10 @@ handle_subscript(
        // the next line then consume the line break.
        p = eval_next_non_blank(*arg, evalarg, &getnext);
        if (getnext
-           && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1]))
+           && ((*p == '.'
+                   && ((rettv->v_type == VAR_DICT && eval_isdictc(p[1]))
+                       || rettv->v_type == VAR_CLASS
+                       || rettv->v_type == VAR_OBJECT))
                || (p[0] == '-' && p[1] == '>' && (p[2] == '{'
                        || ASCII_ISALPHA(in_vim9script() ? *skipwhite(p + 2)
                                                                    : p[2])))))
index 03798268a299c97d2f68aa979ccea20bb282fe54..a3fdbdb9c33cdfa6b54f001127494f060ec743e0 100644 (file)
@@ -439,6 +439,32 @@ def Test_class_object_member_access()
       var c = MyCar.new("def")
   END
   v9.CheckScriptFailure(lines, 'E1041:')
+
+  lines =<< trim END
+      vim9script
+
+      class Foo
+        this.x: list<number> = []
+
+        def Add(n: number): any
+          this.x->add(n)
+          return this
+        enddef
+      endclass
+
+      echo Foo.new().Add(1).Add(2).x
+      echo Foo.new().Add(1).Add(2)
+            .x
+      echo Foo.new().Add(1)
+            .Add(2).x
+      echo Foo.new()
+            .Add(1).Add(2).x
+      echo Foo.new()
+            .Add(1) 
+            .Add(2)
+            .x
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 def Test_class_object_compare()
index 9eff9696b1b496cb89c474db4cd8d0378b189ffc..f21a1887aed96d49b89ac560495c7ac8d0442971 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1239,
 /**/
     1238,
 /**/