mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
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 <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
5d03525cde
commit
1ace49fb98
@ -2551,6 +2551,12 @@ eval_func(
|
|||||||
funcexe.fe_lastline = curwin->w_cursor.lnum;
|
funcexe.fe_lastline = curwin->w_cursor.lnum;
|
||||||
funcexe.fe_evaluate = evaluate;
|
funcexe.fe_evaluate = evaluate;
|
||||||
funcexe.fe_partial = partial;
|
funcexe.fe_partial = partial;
|
||||||
|
if (partial != NULL)
|
||||||
|
{
|
||||||
|
funcexe.fe_object = partial->pt_obj;
|
||||||
|
if (funcexe.fe_object != NULL)
|
||||||
|
++funcexe.fe_object->obj_refcount;
|
||||||
|
}
|
||||||
funcexe.fe_basetv = basetv;
|
funcexe.fe_basetv = basetv;
|
||||||
funcexe.fe_check_type = type;
|
funcexe.fe_check_type = type;
|
||||||
funcexe.fe_found_var = found_var;
|
funcexe.fe_found_var = found_var;
|
||||||
|
@ -7510,6 +7510,21 @@ def Test_object_funcref()
|
|||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
# Using object method funcref at the script level
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
class A
|
||||||
|
this.val: number
|
||||||
|
def Foo(): number
|
||||||
|
return this.val
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
var a = A.new(345)
|
||||||
|
var Fn = a.Foo
|
||||||
|
assert_equal(345, Fn())
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
# Using object method funcref from another object method
|
# Using object method funcref from another object method
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@ -7604,6 +7619,26 @@ def Test_object_funcref()
|
|||||||
a.Bar()
|
a.Bar()
|
||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
# Using object method funcref using call()
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
class A
|
||||||
|
this.val: number
|
||||||
|
def Foo(): number
|
||||||
|
return this.val
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
|
||||||
|
def Bar(obj: A)
|
||||||
|
assert_equal(123, call(obj.Foo, []))
|
||||||
|
enddef
|
||||||
|
|
||||||
|
var a = A.new(123)
|
||||||
|
Bar(a)
|
||||||
|
assert_equal(123, call(a.Foo, []))
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Test for using a class method as a funcref
|
" Test for using a class method as a funcref
|
||||||
@ -7637,6 +7672,21 @@ def Test_class_funcref()
|
|||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
# Using class method funcref at the script level
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
class A
|
||||||
|
public static val: number
|
||||||
|
static def Foo(): number
|
||||||
|
return val
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
A.val = 567
|
||||||
|
var Fn = A.Foo
|
||||||
|
assert_equal(567, Fn())
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
# Using function() to get a class method funcref
|
# Using function() to get a class method funcref
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@ -7725,6 +7775,25 @@ def Test_class_funcref()
|
|||||||
A.Bar()
|
A.Bar()
|
||||||
END
|
END
|
||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
|
|
||||||
|
# Using class method funcref using call()
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
class A
|
||||||
|
public static val: number
|
||||||
|
static def Foo(): number
|
||||||
|
return val
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
|
||||||
|
def Bar()
|
||||||
|
A.val = 468
|
||||||
|
assert_equal(468, call(A.Foo, []))
|
||||||
|
enddef
|
||||||
|
Bar()
|
||||||
|
assert_equal(468, call(A.Foo, []))
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Test for using an object member as a funcref
|
" Test for using an object member as a funcref
|
||||||
|
@ -3540,6 +3540,12 @@ func_call(
|
|||||||
funcexe.fe_lastline = curwin->w_cursor.lnum;
|
funcexe.fe_lastline = curwin->w_cursor.lnum;
|
||||||
funcexe.fe_evaluate = TRUE;
|
funcexe.fe_evaluate = TRUE;
|
||||||
funcexe.fe_partial = partial;
|
funcexe.fe_partial = partial;
|
||||||
|
if (partial != NULL)
|
||||||
|
{
|
||||||
|
funcexe.fe_object = partial->pt_obj;
|
||||||
|
if (funcexe.fe_object != NULL)
|
||||||
|
++funcexe.fe_object->obj_refcount;
|
||||||
|
}
|
||||||
funcexe.fe_selfdict = selfdict;
|
funcexe.fe_selfdict = selfdict;
|
||||||
r = call_func(name, -1, rettv, argc, argv, &funcexe);
|
r = call_func(name, -1, rettv, argc, argv, &funcexe);
|
||||||
}
|
}
|
||||||
@ -3580,6 +3586,12 @@ call_callback(
|
|||||||
CLEAR_FIELD(funcexe);
|
CLEAR_FIELD(funcexe);
|
||||||
funcexe.fe_evaluate = TRUE;
|
funcexe.fe_evaluate = TRUE;
|
||||||
funcexe.fe_partial = callback->cb_partial;
|
funcexe.fe_partial = callback->cb_partial;
|
||||||
|
if (callback->cb_partial != NULL)
|
||||||
|
{
|
||||||
|
funcexe.fe_object = callback->cb_partial->pt_obj;
|
||||||
|
if (funcexe.fe_object != NULL)
|
||||||
|
++funcexe.fe_object->obj_refcount;
|
||||||
|
}
|
||||||
++callback_depth;
|
++callback_depth;
|
||||||
ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe);
|
ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe);
|
||||||
--callback_depth;
|
--callback_depth;
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2029,
|
||||||
/**/
|
/**/
|
||||||
2028,
|
2028,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user