patch 9.0.1558: wrong error for unreachable code after :throw
Problem: Wrong error for unreachable code after :throw.
Solution: Adjust the error message.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 03a6e2c..265f846 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3485,7 +3485,7 @@
}
}
- 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 @@
&& 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 @@
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 @@
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;