patch 9.1.0975: Vim9: interpolated string expr not working in object methods
Commit: https://github.com/vim/vim/commit/b0206e9fb58c8a1c0e0b032f11ce056952182786 Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Mon Dec 30 09:52:16 2024 +0100 patch 9.1.0975: Vim9: interpolated string expr not working in object methods Problem: Vim9: interpolated string expr not working in object methods (Igbanam Ogbuluijah) Solution: Check the evalarg argument (Yegappan Lakshmanan) fixes: #16317 closes: #16342 Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/eval.c b/src/eval.c index f4f8c058d..306cfe7f4 100644 --- a/src/eval.c +++ b/src/eval.c @@ -819,6 +819,8 @@ deref_function_name( typval_T ref; char_u *name = *arg; int save_flags = 0; + int evaluate = evalarg != NULL + && (evalarg->eval_flags & EVAL_EVALUATE); ref.v_type = VAR_UNKNOWN; if (evalarg != NULL) @@ -867,7 +869,7 @@ deref_function_name( *tofree = name; } } - else + else if (evaluate) { if (verbose) semsg(_(e_not_callable_type_str), name); diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 75f1b501d..309898bb6 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -11657,4 +11657,46 @@ def Test_mapnew_with_instance_method() v9.CheckSourceSuccess(lines) enddef +" Test for using an object method in a method call. +def Test_use_object_method_in_a_method_call() + var lines =<< trim END + vim9script + + class Foo + def Cost(nums: list<number>): number + return nums[0] * nums[1] + enddef + + def ShowCost(): string + var g = [4, 5] + return $"Cost is: {g->this.Cost()}" + enddef + endclass + + var d = Foo.new() + assert_equal('Cost is: 20', d.ShowCost()) + END + v9.CheckSourceSuccess(lines) + + # Test for using a non-existing object method in string interpolation + lines =<< trim END + vim9script + + class Foo + def Cost(nums: list<number>): number + return nums[0] * nums[1] + enddef + + def ShowCost(): string + var g = [4, 5] + echo $"Cost is: {g->this.NewCost()}" + enddef + endclass + + var d = Foo.new() + d.ShowCost() + END + v9.CheckSourceFailure(lines, 'E1326: Variable "NewCost" not found in object "Foo"') +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index 3e3d9b29c..ca353c28c 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 */ +/**/ + 975, /**/ 974, /**/ -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tSBd9-00DPYW-7M%40256bit.org.