patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Problem: Vim9: crash when using :trow in a not executed block.
Solution: Don't generate the instruction when skipping. (closes #7659)
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 1066a1d..d567de7 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -324,7 +324,7 @@
echo 'none'
endfunc
-def Test_try_catch()
+def Test_try_catch_throw()
var l = []
try # comment
add(l, '1')
@@ -558,6 +558,12 @@
assert_equal(411, n)
enddef
+def Test_throw_skipped()
+ if 0
+ throw dontgethere
+ endif
+enddef
+
def DeletedFunc(): list<any>
return ['delete me']
enddef
diff --git a/src/version.c b/src/version.c
index 2a6e1da..0a3cd54 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2330,
+/**/
2329,
/**/
2328,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index bcbc57d..0064bd2 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -474,8 +474,10 @@
isn_T *isn;
isntype_T isntype = ISN_2STRING;
garray_T *stack = &cctx->ctx_type_stack;
- type_T **type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
+ type_T **type;
+ RETURN_OK_IF_SKIP(cctx);
+ type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
switch ((*type)->tt_type)
{
// nothing to be done
@@ -7461,6 +7463,8 @@
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
+ if (cctx->ctx_skip == SKIP_YES)
+ return p;
if (may_generate_2STRING(-1, cctx) == FAIL)
return NULL;
if (generate_instr_drop(cctx, ISN_THROW, 1) == NULL)