Mercurial > vim
changeset 22926:edfbb06cd0ee v8.2.2010
patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Commit: https://github.com/vim/vim/commit/8e02faf4e903e33e41961ba042bb5146213813a5
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 18 16:35:02 2020 +0100
patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Problem: Vim9: compiling fails for unreachable return statement.
Solution: Fix it. (closes https://github.com/vim/vim/issues/7319)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Nov 2020 16:45:03 +0100 |
parents | c279a7c8d834 |
children | 84028b392f37 |
files | src/testdir/test_vim9_disassemble.vim src/version.c src/vim9compile.c |
diffstat | 3 files changed, 25 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -749,6 +749,9 @@ def Test_disassemble_const_expr() enddef def ReturnInIf(): string + if 1 < 0 + return "maybe" + endif if g:cond return "yes" else @@ -759,6 +762,9 @@ enddef def Test_disassemble_return_in_if() var instr = execute('disassemble ReturnInIf') assert_match('ReturnInIf\_s*' .. + 'if 1 < 0\_s*' .. + ' return "maybe"\_s*' .. + 'endif\_s*' .. 'if g:cond\_s*' .. '0 LOADG g:cond\_s*' .. '1 COND2BOOL\_s*' ..
--- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2010, +/**/ 2009, /**/ 2008,
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -4694,21 +4694,24 @@ compile_return(char_u *arg, int set_retu if (compile_expr0(&p, cctx) == FAIL) return NULL; - stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; - if (set_return_type) - cctx->ctx_ufunc->uf_ret_type = stack_type; - else - { - if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID - && stack_type->tt_type != VAR_VOID - && stack_type->tt_type != VAR_UNKNOWN) + if (cctx->ctx_skip != SKIP_YES) + { + stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; + if (set_return_type) + cctx->ctx_ufunc->uf_ret_type = stack_type; + else { - emsg(_(e_returning_value_in_function_without_return_type)); - return NULL; + if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID + && stack_type->tt_type != VAR_VOID + && stack_type->tt_type != VAR_UNKNOWN) + { + emsg(_(e_returning_value_in_function_without_return_type)); + return NULL; + } + if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, + cctx, FALSE, FALSE) == FAIL) + return NULL; } - if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, - cctx, FALSE, FALSE) == FAIL) - return NULL; } } else @@ -4725,8 +4728,7 @@ compile_return(char_u *arg, int set_retu // No argument, return zero. generate_PUSHNR(cctx, 0); } - - if (generate_instr(cctx, ISN_RETURN) == NULL) + if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL) return NULL; // "return val | endif" is possible