mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.1223: Vim9: invalid type error for function default value
Problem: Vim9: invalid type error for function default value. Solution: Use right argument index. (closes #6458)
This commit is contained in:
parent
657a826c07
commit
e30f64b4b5
@ -104,11 +104,19 @@ def MyDefaultArgs(name = 'string'): string
|
|||||||
return name
|
return name
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def MyDefaultSecond(name: string, second: bool = true): string
|
||||||
|
return second ? name : 'none'
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_call_default_args()
|
def Test_call_default_args()
|
||||||
assert_equal('string', MyDefaultArgs())
|
assert_equal('string', MyDefaultArgs())
|
||||||
assert_equal('one', MyDefaultArgs('one'))
|
assert_equal('one', MyDefaultArgs('one'))
|
||||||
assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
|
assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
|
||||||
|
|
||||||
|
assert_equal('test', MyDefaultSecond('test'))
|
||||||
|
assert_equal('test', MyDefaultSecond('test', true))
|
||||||
|
assert_equal('none', MyDefaultSecond('test', false))
|
||||||
|
|
||||||
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
|
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
|
||||||
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string')
|
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string')
|
||||||
enddef
|
enddef
|
||||||
|
@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1223,
|
||||||
/**/
|
/**/
|
||||||
1222,
|
1222,
|
||||||
/**/
|
/**/
|
||||||
|
@ -6865,7 +6865,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
|
|||||||
val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
|
if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
|
||||||
ufunc->uf_arg_types[arg_idx] = val_type;
|
ufunc->uf_arg_types[arg_idx] = val_type;
|
||||||
else if (check_type(ufunc->uf_arg_types[i], val_type, FALSE)
|
else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE)
|
||||||
== FAIL)
|
== FAIL)
|
||||||
{
|
{
|
||||||
arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type,
|
arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user