forked from aniani/vim
patch 8.2.1261: Vim9: common type of function not tested
Problem: Vim9: common type of function not tested. Solution: Add a test. Fix uncovered problems.
This commit is contained in:
@@ -3,6 +3,15 @@
|
|||||||
source check.vim
|
source check.vim
|
||||||
source vim9.vim
|
source vim9.vim
|
||||||
|
|
||||||
|
|
||||||
|
let g:cond = v:false
|
||||||
|
def FuncOne(arg: number): string
|
||||||
|
return 'yes'
|
||||||
|
enddef
|
||||||
|
def FuncTwo(arg: number): number
|
||||||
|
return 123
|
||||||
|
enddef
|
||||||
|
|
||||||
" test cond ? expr : expr
|
" test cond ? expr : expr
|
||||||
def Test_expr1()
|
def Test_expr1()
|
||||||
assert_equal('one', true ? 'one' : 'two')
|
assert_equal('one', true ? 'one' : 'two')
|
||||||
@@ -43,6 +52,11 @@ def Test_expr1()
|
|||||||
let RetTwo: func(string): number = function('winnr')
|
let RetTwo: func(string): number = function('winnr')
|
||||||
let RetThat: func = g:atrue ? RetOne : RetTwo
|
let RetThat: func = g:atrue ? RetOne : RetTwo
|
||||||
assert_equal(function('len'), RetThat)
|
assert_equal(function('len'), RetThat)
|
||||||
|
|
||||||
|
let x = FuncOne
|
||||||
|
let y = FuncTwo
|
||||||
|
let Z = g:cond ? FuncOne : FuncTwo
|
||||||
|
assert_equal(123, Z(3))
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr1_vimscript()
|
def Test_expr1_vimscript()
|
||||||
@@ -88,6 +102,13 @@ func Test_expr1_fails()
|
|||||||
call CheckDefFailure(["let x = 1 ? 'one': 'two'"], msg)
|
call CheckDefFailure(["let x = 1 ? 'one': 'two'"], msg)
|
||||||
call CheckDefFailure(["let x = 1 ? 'one' :'two'"], msg)
|
call CheckDefFailure(["let x = 1 ? 'one' :'two'"], msg)
|
||||||
call CheckDefFailure(["let x = 1 ? 'one':'two'"], msg)
|
call CheckDefFailure(["let x = 1 ? 'one':'two'"], msg)
|
||||||
|
|
||||||
|
" missing argument detected even when common type is used
|
||||||
|
call CheckDefFailure([
|
||||||
|
\ 'let x = FuncOne',
|
||||||
|
\ 'let y = FuncTwo',
|
||||||
|
\ 'let Z = g:cond ? FuncOne : FuncTwo',
|
||||||
|
\ 'Z()'], 'E119:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" TODO: define inside test function
|
" TODO: define inside test function
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1261,
|
||||||
/**/
|
/**/
|
||||||
1260,
|
1260,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1143,13 +1143,13 @@ generate_GETITEM(cctx_T *cctx, int index)
|
|||||||
|
|
||||||
RETURN_OK_IF_SKIP(cctx);
|
RETURN_OK_IF_SKIP(cctx);
|
||||||
|
|
||||||
if (type->tt_type == VAR_LIST)
|
if (type->tt_type != VAR_LIST)
|
||||||
item_type = type->tt_member;
|
|
||||||
else if (type->tt_type != VAR_ANY)
|
|
||||||
{
|
{
|
||||||
|
// cannot happen, caller has checked the type
|
||||||
emsg(_(e_listreq));
|
emsg(_(e_listreq));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
item_type = type->tt_member;
|
||||||
if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL)
|
if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
isn->isn_arg.number = index;
|
isn->isn_arg.number = index;
|
||||||
@@ -4969,6 +4969,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
|
|
||||||
if (var_count > 0 && is_decl)
|
if (var_count > 0 && is_decl)
|
||||||
{
|
{
|
||||||
|
// TODO: should we allow this, and figure out type inference from list
|
||||||
|
// members?
|
||||||
emsg(_("E1092: Cannot use a list for a declaration"));
|
emsg(_("E1092: Cannot use a list for a declaration"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -2470,6 +2470,7 @@ func_return:
|
|||||||
if (func_return(&ectx) == FAIL)
|
if (func_return(&ectx) == FAIL)
|
||||||
// only fails when out of memory
|
// only fails when out of memory
|
||||||
goto failed;
|
goto failed;
|
||||||
|
continue;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
if (trylevel == 0)
|
if (trylevel == 0)
|
||||||
|
Reference in New Issue
Block a user