mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.0206: calling Vim9 function using default argument fails
Problem: Calling Vim9 function using default argument fails. Solution: Give an appropriate error. (closes #5572)
This commit is contained in:
@@ -131,6 +131,34 @@ def Test_call_varargs()
|
|||||||
assert_equal('one,two,three', MyVarargs('one', 'two', 'three'))
|
assert_equal('one,two,three', MyVarargs('one', 'two', 'three'))
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
"def Test_call_func_defined_later()
|
||||||
|
" call assert_equal('one', DefineLater('one'))
|
||||||
|
" call assert_fails('call NotDefined("one")', 'E99:')
|
||||||
|
"enddef
|
||||||
|
|
||||||
|
func DefineLater(arg)
|
||||||
|
return a:arg
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
def MyDefaultArgs(name = 'string'): string
|
||||||
|
return name
|
||||||
|
enddef
|
||||||
|
|
||||||
|
func Test_call_default_args_from_func()
|
||||||
|
" TODO: implement using default value for optional argument
|
||||||
|
"call assert_equal('string', MyDefaultArgs())
|
||||||
|
call assert_fails('call MyDefaultArgs()', 'optional arguments not implemented yet')
|
||||||
|
call assert_equal('one', MyDefaultArgs('one'))
|
||||||
|
call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
def Test_call_default_args()
|
||||||
|
" TODO: implement using default value for optional argument
|
||||||
|
"assert_equal('string', MyDefaultArgs())
|
||||||
|
assert_equal('one', MyDefaultArgs('one'))
|
||||||
|
assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_return_type_wrong()
|
def Test_return_type_wrong()
|
||||||
" TODO: why is ! needed for Mac and FreeBSD?
|
" TODO: why is ! needed for Mac and FreeBSD?
|
||||||
CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
|
CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
|
||||||
|
@@ -742,6 +742,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 */
|
||||||
|
/**/
|
||||||
|
206,
|
||||||
/**/
|
/**/
|
||||||
205,
|
205,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1024,9 +1024,11 @@ generate_UCALL(cctx_T *cctx, char_u *name, int argcount)
|
|||||||
isn->isn_arg.ufunc.cuf_argcount = argcount;
|
isn->isn_arg.ufunc.cuf_argcount = argcount;
|
||||||
|
|
||||||
stack->ga_len -= argcount; // drop the arguments
|
stack->ga_len -= argcount; // drop the arguments
|
||||||
|
if (ga_grow(stack, 1) == FAIL)
|
||||||
// drop the funcref/partial, get back the return value
|
return FAIL;
|
||||||
((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_any;
|
// add return value
|
||||||
|
((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
|
||||||
|
++stack->ga_len;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@@ -362,6 +362,7 @@ call_def_function(
|
|||||||
int idx;
|
int idx;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
dfunc_T *dfunc;
|
dfunc_T *dfunc;
|
||||||
|
int optcount = ufunc_argcount(ufunc) - argc;
|
||||||
|
|
||||||
// Get pointer to item in the stack.
|
// Get pointer to item in the stack.
|
||||||
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
|
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
|
||||||
@@ -392,6 +393,12 @@ call_def_function(
|
|||||||
ectx.ec_frame = ectx.ec_stack.ga_len;
|
ectx.ec_frame = ectx.ec_stack.ga_len;
|
||||||
initial_frame_ptr = ectx.ec_frame;
|
initial_frame_ptr = ectx.ec_frame;
|
||||||
|
|
||||||
|
// TODO: Put omitted argument default values on the stack.
|
||||||
|
if (optcount > 0)
|
||||||
|
{
|
||||||
|
emsg("optional arguments not implemented yet");
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
// dummy frame entries
|
// dummy frame entries
|
||||||
for (idx = 0; idx < STACK_FRAME_SIZE; ++idx)
|
for (idx = 0; idx < STACK_FRAME_SIZE; ++idx)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user