forked from aniani/vim
patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Problem: Vim9: compiling fails for unreachable return statement. Solution: Fix it. (closes #7319)
This commit is contained in:
@@ -749,6 +749,9 @@ def Test_disassemble_const_expr()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def ReturnInIf(): string
|
def ReturnInIf(): string
|
||||||
|
if 1 < 0
|
||||||
|
return "maybe"
|
||||||
|
endif
|
||||||
if g:cond
|
if g:cond
|
||||||
return "yes"
|
return "yes"
|
||||||
else
|
else
|
||||||
@@ -759,6 +762,9 @@ enddef
|
|||||||
def Test_disassemble_return_in_if()
|
def Test_disassemble_return_in_if()
|
||||||
var instr = execute('disassemble ReturnInIf')
|
var instr = execute('disassemble ReturnInIf')
|
||||||
assert_match('ReturnInIf\_s*' ..
|
assert_match('ReturnInIf\_s*' ..
|
||||||
|
'if 1 < 0\_s*' ..
|
||||||
|
' return "maybe"\_s*' ..
|
||||||
|
'endif\_s*' ..
|
||||||
'if g:cond\_s*' ..
|
'if g:cond\_s*' ..
|
||||||
'0 LOADG g:cond\_s*' ..
|
'0 LOADG g:cond\_s*' ..
|
||||||
'1 COND2BOOL\_s*' ..
|
'1 COND2BOOL\_s*' ..
|
||||||
|
@@ -750,6 +750,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 */
|
||||||
|
/**/
|
||||||
|
2010,
|
||||||
/**/
|
/**/
|
||||||
2009,
|
2009,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -4694,6 +4694,8 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
|
|||||||
if (compile_expr0(&p, cctx) == FAIL)
|
if (compile_expr0(&p, cctx) == FAIL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (cctx->ctx_skip != SKIP_YES)
|
||||||
|
{
|
||||||
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
if (set_return_type)
|
if (set_return_type)
|
||||||
cctx->ctx_ufunc->uf_ret_type = stack_type;
|
cctx->ctx_ufunc->uf_ret_type = stack_type;
|
||||||
@@ -4711,6 +4713,7 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// "set_return_type" cannot be TRUE, only used for a lambda which
|
// "set_return_type" cannot be TRUE, only used for a lambda which
|
||||||
@@ -4725,8 +4728,7 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
|
|||||||
// No argument, return zero.
|
// No argument, return zero.
|
||||||
generate_PUSHNR(cctx, 0);
|
generate_PUSHNR(cctx, 0);
|
||||||
}
|
}
|
||||||
|
if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL)
|
||||||
if (generate_instr(cctx, ISN_RETURN) == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// "return val | endif" is possible
|
// "return val | endif" is possible
|
||||||
|
Reference in New Issue
Block a user