patch 9.0.1805: Vim9: problem compiling object method as function call arg

Commit: 
https://github.com/vim/vim/commit/639751d218ef423efef8e9aa0fa9abaff7122186
Author: Yegappan Lakshmanan <[email protected]>
Date:   Sun Aug 27 19:23:37 2023 +0200

    patch 9.0.1805: Vim9: problem compiling object method as function call arg
    
    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 <[email protected]>
    Co-authored-by: Yegappan Lakshmanan <[email protected]>

diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index bfe203289..f7d6b73f4 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 8b66b3341..39cac791f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1805,
 /**/
     1804,
 /**/
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 3e9c6b6e8..ba1aa0c1d 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -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);
 }

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qaJaS-003Pvo-2t%40256bit.org.

Raspunde prin e-mail lui