Skip to content

Commit b0206e9

Browse files
yegappanchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent df4b3ca commit b0206e9

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/eval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ deref_function_name(
819819
typval_T ref;
820820
char_u *name = *arg;
821821
int save_flags = 0;
822+
int evaluate = evalarg != NULL
823+
&& (evalarg->eval_flags & EVAL_EVALUATE);
822824

823825
ref.v_type = VAR_UNKNOWN;
824826
if (evalarg != NULL)
@@ -867,7 +869,7 @@ deref_function_name(
867869
*tofree = name;
868870
}
869871
}
870-
else
872+
else if (evaluate)
871873
{
872874
if (verbose)
873875
semsg(_(e_not_callable_type_str), name);

src/testdir/test_vim9_class.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11657,4 +11657,46 @@ def Test_mapnew_with_instance_method()
1165711657
v9.CheckSourceSuccess(lines)
1165811658
enddef
1165911659

11660+
" Test for using an object method in a method call.
11661+
def Test_use_object_method_in_a_method_call()
11662+
var lines =<< trim END
11663+
vim9script
11664+
11665+
class Foo
11666+
def Cost(nums: list<number>): number
11667+
return nums[0] * nums[1]
11668+
enddef
11669+
11670+
def ShowCost(): string
11671+
var g = [4, 5]
11672+
return $"Cost is: {g->this.Cost()}"
11673+
enddef
11674+
endclass
11675+
11676+
var d = Foo.new()
11677+
assert_equal('Cost is: 20', d.ShowCost())
11678+
END
11679+
v9.CheckSourceSuccess(lines)
11680+
11681+
# Test for using a non-existing object method in string interpolation
11682+
lines =<< trim END
11683+
vim9script
11684+
11685+
class Foo
11686+
def Cost(nums: list<number>): number
11687+
return nums[0] * nums[1]
11688+
enddef
11689+
11690+
def ShowCost(): string
11691+
var g = [4, 5]
11692+
echo $"Cost is: {g->this.NewCost()}"
11693+
enddef
11694+
endclass
11695+
11696+
var d = Foo.new()
11697+
d.ShowCost()
11698+
END
11699+
v9.CheckSourceFailure(lines, 'E1326: Variable "NewCost" not found in object "Foo"')
11700+
enddef
11701+
1166011702
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
975,
707709
/**/
708710
974,
709711
/**/

0 commit comments

Comments
 (0)