summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-18 16:35:02 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-18 16:35:02 +0100
commit8e02faf4e903e33e41961ba042bb5146213813a5 (patch)
treee9bb3ee054bd7a1291b2fd2d5e822a6d6f8c98d4 /src/vim9compile.c
parent382319211a96adce089673c80eda982cc5259d0d (diff)
downloadvim-git-8e02faf4e903e33e41961ba042bb5146213813a5.tar.gz
patch 8.2.2010: Vim9: compiling fails for unreachable return statementv8.2.2010
Problem: Vim9: compiling fails for unreachable return statement. Solution: Fix it. (closes #7319)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index c8fb95ec4..c5d92aa1b 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4694,21 +4694,24 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
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_skip != SKIP_YES)
{
- if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
- && stack_type->tt_type != VAR_VOID
- && stack_type->tt_type != VAR_UNKNOWN)
+ 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 (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
+ 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;
+ return NULL;
+ }
}
}
else
@@ -4725,8 +4728,7 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
// 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