patch 9.1.0976: Vim9: missing return statement with throw
Problem: Vim9: missing return statement with throw
(atitcreate)
Solution: Treat a throw statement at the end of an if-else block as a
return statement (Yegappan Lakshmanan)
fixes: #16312
closes: #16338
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/vim9cmds.c b/src/vim9cmds.c
index c7fa60a..f8ebfb1 100644
--- a/src/vim9cmds.c
+++ b/src/vim9cmds.c
@@ -602,7 +602,9 @@
return NULL;
}
unwind_locals(cctx, scope->se_local_count, TRUE);
- if (!cctx->ctx_had_return)
+ if (!cctx->ctx_had_return && !cctx->ctx_had_throw)
+ // the previous if block didn't end in a "return" or a "throw"
+ // statement.
scope->se_u.se_if.is_had_return = FALSE;
if (cctx->ctx_skip == SKIP_NOT)
@@ -749,7 +751,9 @@
return NULL;
}
unwind_locals(cctx, scope->se_local_count, TRUE);
- if (!cctx->ctx_had_return)
+ if (!cctx->ctx_had_return && !cctx->ctx_had_throw)
+ // the previous if block didn't end in a "return" or a "throw"
+ // statement.
scope->se_u.se_if.is_had_return = FALSE;
scope->se_u.se_if.is_seen_else = TRUE;
@@ -821,7 +825,9 @@
}
ifscope = &scope->se_u.se_if;
unwind_locals(cctx, scope->se_local_count, TRUE);
- if (!cctx->ctx_had_return)
+ if (!cctx->ctx_had_return && !cctx->ctx_had_throw)
+ // the previous if block didn't end in a "return" or a "throw"
+ // statement.
ifscope->is_had_return = FALSE;
if (scope->se_u.se_if.is_if_label >= 0)