Skip to content

Commit 1ace49f

Browse files
yegappanchrisbra
authored andcommitted
patch 9.0.2029: Vim9: no support for partials using call()
Problem: Vim9: no support for partials using call() Solution: Add support closes: #13341 Signed-off-by: Christian Brabandt <[email protected]> Co-authored-by: Yegappan Lakshmanan <[email protected]>
1 parent 5d03525 commit 1ace49f

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

src/eval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,12 @@ eval_func(
25512551
funcexe.fe_lastline = curwin->w_cursor.lnum;
25522552
funcexe.fe_evaluate = evaluate;
25532553
funcexe.fe_partial = partial;
2554+
if (partial != NULL)
2555+
{
2556+
funcexe.fe_object = partial->pt_obj;
2557+
if (funcexe.fe_object != NULL)
2558+
++funcexe.fe_object->obj_refcount;
2559+
}
25542560
funcexe.fe_basetv = basetv;
25552561
funcexe.fe_check_type = type;
25562562
funcexe.fe_found_var = found_var;

src/testdir/test_vim9_class.vim

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7510,6 +7510,21 @@ def Test_object_funcref()
75107510
END
75117511
v9.CheckSourceSuccess(lines)
75127512

7513+
# Using object method funcref at the script level
7514+
lines =<< trim END
7515+
vim9script
7516+
class A
7517+
this.val: number
7518+
def Foo(): number
7519+
return this.val
7520+
enddef
7521+
endclass
7522+
var a = A.new(345)
7523+
var Fn = a.Foo
7524+
assert_equal(345, Fn())
7525+
END
7526+
v9.CheckSourceSuccess(lines)
7527+
75137528
# Using object method funcref from another object method
75147529
lines =<< trim END
75157530
vim9script
@@ -7604,6 +7619,26 @@ def Test_object_funcref()
76047619
a.Bar()
76057620
END
76067621
v9.CheckSourceSuccess(lines)
7622+
7623+
# Using object method funcref using call()
7624+
lines =<< trim END
7625+
vim9script
7626+
class A
7627+
this.val: number
7628+
def Foo(): number
7629+
return this.val
7630+
enddef
7631+
endclass
7632+
7633+
def Bar(obj: A)
7634+
assert_equal(123, call(obj.Foo, []))
7635+
enddef
7636+
7637+
var a = A.new(123)
7638+
Bar(a)
7639+
assert_equal(123, call(a.Foo, []))
7640+
END
7641+
v9.CheckSourceSuccess(lines)
76077642
enddef
76087643

76097644
" Test for using a class method as a funcref
@@ -7637,6 +7672,21 @@ def Test_class_funcref()
76377672
END
76387673
v9.CheckSourceSuccess(lines)
76397674

7675+
# Using class method funcref at the script level
7676+
lines =<< trim END
7677+
vim9script
7678+
class A
7679+
public static val: number
7680+
static def Foo(): number
7681+
return val
7682+
enddef
7683+
endclass
7684+
A.val = 567
7685+
var Fn = A.Foo
7686+
assert_equal(567, Fn())
7687+
END
7688+
v9.CheckSourceSuccess(lines)
7689+
76407690
# Using function() to get a class method funcref
76417691
lines =<< trim END
76427692
vim9script
@@ -7725,6 +7775,25 @@ def Test_class_funcref()
77257775
A.Bar()
77267776
END
77277777
v9.CheckSourceSuccess(lines)
7778+
7779+
# Using class method funcref using call()
7780+
lines =<< trim END
7781+
vim9script
7782+
class A
7783+
public static val: number
7784+
static def Foo(): number
7785+
return val
7786+
enddef
7787+
endclass
7788+
7789+
def Bar()
7790+
A.val = 468
7791+
assert_equal(468, call(A.Foo, []))
7792+
enddef
7793+
Bar()
7794+
assert_equal(468, call(A.Foo, []))
7795+
END
7796+
v9.CheckSourceSuccess(lines)
77287797
enddef
77297798

77307799
" Test for using an object member as a funcref

src/userfunc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,12 @@ func_call(
35403540
funcexe.fe_lastline = curwin->w_cursor.lnum;
35413541
funcexe.fe_evaluate = TRUE;
35423542
funcexe.fe_partial = partial;
3543+
if (partial != NULL)
3544+
{
3545+
funcexe.fe_object = partial->pt_obj;
3546+
if (funcexe.fe_object != NULL)
3547+
++funcexe.fe_object->obj_refcount;
3548+
}
35433549
funcexe.fe_selfdict = selfdict;
35443550
r = call_func(name, -1, rettv, argc, argv, &funcexe);
35453551
}
@@ -3580,6 +3586,12 @@ call_callback(
35803586
CLEAR_FIELD(funcexe);
35813587
funcexe.fe_evaluate = TRUE;
35823588
funcexe.fe_partial = callback->cb_partial;
3589+
if (callback->cb_partial != NULL)
3590+
{
3591+
funcexe.fe_object = callback->cb_partial->pt_obj;
3592+
if (funcexe.fe_object != NULL)
3593+
++funcexe.fe_object->obj_refcount;
3594+
}
35833595
++callback_depth;
35843596
ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe);
35853597
--callback_depth;

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+
2029,
707709
/**/
708710
2028,
709711
/**/

0 commit comments

Comments
 (0)