0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -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:
Bram Moolenaar
2020-02-04 21:24:15 +01:00
parent a5edb670dc
commit 26e117e9bc
4 changed files with 42 additions and 3 deletions

View File

@@ -131,6 +131,34 @@ def Test_call_varargs()
assert_equal('one,two,three', MyVarargs('one', 'two', 'three'))
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()
" TODO: why is ! needed for Mac and FreeBSD?
CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
206,
/**/
205,
/**/

View File

@@ -1024,9 +1024,11 @@ generate_UCALL(cctx_T *cctx, char_u *name, int argcount)
isn->isn_arg.ufunc.cuf_argcount = argcount;
stack->ga_len -= argcount; // drop the arguments
// drop the funcref/partial, get back the return value
((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_any;
if (ga_grow(stack, 1) == FAIL)
return FAIL;
// add return value
((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
++stack->ga_len;
return OK;
}

View File

@@ -362,6 +362,7 @@ call_def_function(
int idx;
int ret = FAIL;
dfunc_T *dfunc;
int optcount = ufunc_argcount(ufunc) - argc;
// Get pointer to item in the stack.
#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;
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
for (idx = 0; idx < STACK_FRAME_SIZE; ++idx)
{