Skip to content

Commit

Permalink
patch 8.2.4572: Vim9: return type "any" is changed to first returned …
Browse files Browse the repository at this point in the history
…type

Problem:    Vim9: return type "any" is sometimes changed to first returned
            type.  (Virginia Senioria)
Solution:   Do not change the return type if declared as "any". (closes #9949)
  • Loading branch information
brammool committed Mar 15, 2022
1 parent 8d5e514 commit 1a572e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/testdir/test_vim9_func.vim
Expand Up @@ -535,6 +535,30 @@ def Test_return_list_any()
v9.CheckScriptSuccess(lines)
enddef

def Test_return_any_two_types()
var lines =<< trim END
vim9script

def G(Fn: func(string): any)
g:result = Fn("hello")
enddef

def F(a: number, b: string): any
echo b
if a > 0
return 1
else
return []
endif
enddef

G(function(F, [1]))
END
v9.CheckScriptSuccess(lines)
assert_equal(1, g:result)
unlet g:result
enddef

func s:Increment()
let g:counter += 1
endfunc
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4572,
/**/
4571,
/**/
Expand Down
3 changes: 1 addition & 2 deletions src/vim9cmds.c
Expand Up @@ -2258,8 +2258,7 @@ compile_return(char_u *arg, int check_return_type, int legacy, cctx_T *cctx)
// return type here.
stack_type = get_type_on_stack(cctx, 0);
if ((check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
|| cctx->ctx_ufunc->uf_ret_type == &t_unknown
|| cctx->ctx_ufunc->uf_ret_type == &t_any))
|| cctx->ctx_ufunc->uf_ret_type == &t_unknown))
|| (!check_return_type
&& cctx->ctx_ufunc->uf_ret_type == &t_unknown))
{
Expand Down

0 comments on commit 1a572e9

Please sign in to comment.