patch 9.1.0909: Vim9: crash when calling instance method
Commit:
https://github.com/vim/vim/commit/481992cea9cdb4855db7807e710a5306a124290b
Author: Yegappan Lakshmanan <[email protected]>
Date: Fri Dec 6 18:35:12 2024 +0100
patch 9.1.0909: Vim9: crash when calling instance method
Problem: Vim9: crash when calling instance method
(Igbanam Ogbuluijah)
Solution: Pass the object when calling a partial function
(Yegappan Lakshmanan)
fixes: #16166
closes: #16180
Signed-off-by: Yegappan Lakshmanan <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/eval.c b/src/eval.c
index fabe9643c..6ce591885 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -271,8 +271,10 @@ eval_expr_partial(
return FAIL;
// Shortcut to call a compiled function with minimal overhead.
+ if (partial->pt_obj != NULL)
+ partial->pt_obj->obj_refcount++;
r = call_def_function(partial->pt_func, argc, argv, DEF_USE_PT_ARGV,
- partial, NULL, fc, rettv);
+ partial, partial->pt_obj, fc, rettv);
if (fc_arg == NULL)
remove_funccal();
if (r == FAIL)
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index d8a3fa383..bea0ec91f 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -11596,4 +11596,65 @@ def Test_any_obj_var_type()
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected list<any> but
got string', 1)
enddef
+" Test for using an object method with mapnew()
+def Test_mapnew_with_instance_method()
+ var lines =<< trim END
+ vim9script
+
+ class Foo
+ var str: string
+ var nums: list<number> = [1, 2, 3]
+
+ def InstanceMethod(n: number): string
+ return this.str .. n
+ enddef
+
+ def MapperMethod(idx: number, elem: number): string
+ return elem->this.InstanceMethod()
+ enddef
+
+ def MapTest()
+ this.str = "foo"
+ var l = ['foo1', 'foo2', 'foo3']
+ assert_equal(l, this.nums->mapnew(this.MapperMethod))
+ enddef
+ endclass
+
+ Foo.new().MapTest()
+ END
+ v9.CheckSourceSuccess(lines)
+
+ # Error in the mapnew() function
+ lines =<< trim END
+ vim9script
+
+ class Foo
+ var str: string
+ var nums: list<number> = [1, 2, 3]
+
+ def InstanceMethod(n: number): string
+ throw "InstanceMethod failed"
+ enddef
+
+ def MapperMethod(idx: number, elem: number): string
+ return elem->this.InstanceMethod()
+ enddef
+
+ def MapTest()
+ this.str = "foo"
+ var caught_exception: bool = false
+ try
+ this.nums->mapnew(this.MapperMethod)
+ catch /InstanceMethod failed/
+ caught_exception = true
+ endtry
+ assert_true(caught_exception)
+ enddef
+ endclass
+
+ Foo.new().MapTest()
+ END
+ v9.CheckSourceSuccess(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 4cb67efba..e5d1eb130 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 909,
/**/
908,
/**/
--
--
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 visit
https://groups.google.com/d/msgid/vim_dev/E1tJcNz-00DAVi-9S%40256bit.org.