patch 8.2.4071: Vim9: no detection of return in try/endtry
Problem: Vim9: no detection of return in try/endtry. (Dominique Pellé)
Solution: Check if any of the blocks inside try/endtry did not end in
return.
diff --git a/src/vim9cmds.c b/src/vim9cmds.c
index 3372ad4..5beeab8 100644
--- a/src/vim9cmds.c
+++ b/src/vim9cmds.c
@@ -1343,6 +1343,8 @@
emsg(_(e_catch_unreachable_after_catch_all));
return NULL;
}
+ if (!cctx->ctx_had_return)
+ scope->se_u.se_try.ts_no_return = TRUE;
if (cctx->ctx_skip != SKIP_YES)
{
@@ -1498,6 +1500,7 @@
isn->isn_arg.jump.jump_where = this_instr;
scope->se_u.se_try.ts_catch_label = 0;
}
+ scope->se_u.se_try.ts_has_finally = TRUE;
if (generate_instr(cctx, ISN_FINALLY) == NULL)
return NULL;
}
@@ -1567,6 +1570,14 @@
}
}
+ // If there is a finally clause that ends in return then we will return.
+ // If one of the blocks didn't end in "return" or we did not catch all
+ // exceptions reset the had_return flag.
+ if (!(scope->se_u.se_try.ts_has_finally && cctx->ctx_had_return)
+ && (scope->se_u.se_try.ts_no_return
+ || !scope->se_u.se_try.ts_caught_all))
+ cctx->ctx_had_return = FALSE;
+
compile_endblock(cctx);
if (cctx->ctx_skip != SKIP_YES)