1
0
forked from aniani/vim

patch 9.0.1558: wrong error for unreachable code after :throw

Problem:    Wrong error for unreachable code after :throw.
Solution:   Adjust the error message.
This commit is contained in:
Bram Moolenaar
2023-05-14 22:05:15 +01:00
parent 9d383f30bb
commit a2c0028fdf
5 changed files with 39 additions and 6 deletions

View File

@@ -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;