summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 03a6e2c27..265f84661 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3485,7 +3485,7 @@ compile_def_function(
}
}
- if (cctx.ctx_had_return
+ if ((cctx.ctx_had_return || cctx.ctx_had_throw)
&& ea.cmdidx != CMD_elseif
&& ea.cmdidx != CMD_else
&& ea.cmdidx != CMD_endif
@@ -3496,9 +3496,11 @@ compile_def_function(
&& ea.cmdidx != CMD_endtry
&& !ignore_unreachable_code_for_testing)
{
- emsg(_(e_unreachable_code_after_return));
+ semsg(_(e_unreachable_code_after_str),
+ cctx.ctx_had_return ? "return" : "throw");
goto erret;
}
+ cctx.ctx_had_throw = FALSE;
p = skipwhite(p);
if (ea.cmdidx != CMD_SIZE
@@ -3612,7 +3614,7 @@ compile_def_function(
break;
case CMD_throw:
line = compile_throw(p, &cctx);
- cctx.ctx_had_return = TRUE;
+ cctx.ctx_had_throw = TRUE;
break;
case CMD_eval:
@@ -3765,7 +3767,9 @@ nextline:
goto erret;
}
- if (!cctx.ctx_had_return)
+ // TODO: if a function ends in "throw" but there was a return elsewhere we
+ // should not assume the return type is "void".
+ if (!cctx.ctx_had_return && !cctx.ctx_had_throw)
{
if (ufunc->uf_ret_type->tt_type == VAR_UNKNOWN)
ufunc->uf_ret_type = &t_void;