patch 9.0.1703: Vim9 Calling a method in an extended class fails
Commit:
https://github.com/vim/vim/commit/74cc13cc402fa4df9033fbbc0643b1b403525950
Author: Yegappan Lakshmanan <[email protected]>
Date: Sun Aug 13 17:41:26 2023 +0200
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Problem: Vim9 Calling a method in an extended class fails
Solution: use method index directly
closes: #12778
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 4936c5320..e566a9e64 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -1913,4 +1913,39 @@ def Test_extends_method_crashes_vim()
v9.CheckScriptSuccess(lines)
enddef
+" Test for calling a method in a class that is extended
+def Test_call_method_in_extended_class()
+ var lines =<< trim END
+ vim9script
+
+ var prop_init_called = false
+ var prop_register_called = false
+
+ class Property
+ def Init()
+ prop_init_called = true
+ enddef
+
+ def Register()
+ prop_register_called = true
+ enddef
+ endclass
+
+ class Bool extends Property
+ endclass
+
+ def Observe(obj: Property)
+ obj.Register()
+ enddef
+
+ var p = Property.new()
+ Observe(p)
+
+ p.Init()
+ assert_true(prop_init_called)
+ assert_true(prop_register_called)
+ 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 fc6621fa5..d5091c4e9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1703,
/**/
1702,
/**/
diff --git a/src/vim9class.c b/src/vim9class.c
index 18f36bdb4..2f2422871 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -209,6 +209,13 @@ object_index_from_itf_index(class_T *itf, int is_method,
int idx, class_T *cl)
siemsg("index %d out of range for interface %s", idx, itf->class_name);
return 0;
}
+
+ // If "cl" is the interface or the class that is extended, then the method
+ // index can be used directly and there is no need to search for the method
+ // index in one of the child classes.
+ if (cl == itf)
+ return idx;
+
itf2class_T *i2c;
for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next)
if (i2c->i2c_class == cl && i2c->i2c_is_method == is_method)
--
--
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/E1qVDVc-000Dta-6H%40256bit.org.