]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1805: Vim9: problem compiling object method as function call arg v9.0.1805
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 27 Aug 2023 17:23:37 +0000 (19:23 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 27 Aug 2023 17:26:16 +0000 (19:26 +0200)
Problem:  Vim9: problem compiling object method as function call arg
Solution: After a object/class method call, remove the object/class from
          the stack.

closes: #12081
closes: #12929

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
src/testdir/test_vim9_class.vim
src/version.c
src/vim9instr.c

index bfe203289c3a25e2e62e08c19e27f2303b4eb6f6..f7d6b73f492c405415afbbce61cbe22758b7f6d6 100644 (file)
@@ -3391,4 +3391,51 @@ def Test_interface_private_class_method()
   v9.CheckScriptFailure(lines, 'E1349: Function "_Foo" of interface "Intf" not implemented')
 enddef
 
+" Test for using the return value of a class/object method as a function
+" argument.
+def Test_objmethod_funcarg()
+  var lines =<< trim END
+    vim9script
+
+    class C
+      def Foo(): string
+        return 'foo'
+      enddef
+    endclass
+
+    def Bar(a: number, s: string): string
+      return s
+    enddef
+
+    def Baz(c: C)
+      assert_equal('foo', Bar(10, c.Foo()))
+    enddef
+
+    var t = C.new()
+    Baz(t)
+  END
+  v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+
+    class C
+      static def Foo(): string
+        return 'foo'
+      enddef
+    endclass
+
+    def Bar(a: number, s: string): string
+      return s
+    enddef
+
+    def Baz()
+      assert_equal('foo', Bar(10, C.Foo()))
+    enddef
+
+    Baz()
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 8b66b3341fb712bf11804d952df96ae6b90c4a61..39cac791fa6306abccd9bbf542160486c8f9d3c3 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1805,
 /**/
     1804,
 /**/
index 3e9c6b6e8eb35e0668fa5480898d1737ce79ddca..ba1aa0c1dd25ad74e26984fe470ba16a3ac62f03 100644 (file)
@@ -1902,6 +1902,10 @@ generate_CALL(
     // drop the argument types
     cctx->ctx_type_stack.ga_len -= argcount;
 
+    // For an object or class method call, drop the object/class type
+    if (ufunc->uf_class != NULL)
+       cctx->ctx_type_stack.ga_len--;
+
     // add return type
     return push_type_stack(cctx, ufunc->uf_ret_type);
 }