Patch 8.2.4499
Problem: Vim9: at the script level declarations leak from try block to
catch and finally block.
Solution: End the block and start a new one. (closes #9883)
Files: src/ex_eval.c, src/testdir/test_vim9_script.vim
*** ../vim-8.2.4498/src/ex_eval.c 2022-01-28 15:28:00.208927722 +0000
--- src/ex_eval.c 2022-03-03 15:09:41.714979284 +0000
***************
*** 1827,1832 ****
--- 1827,1842 ----
cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT;
did_emsg = got_int = did_throw = FALSE;
catch_exception((except_T *)cstack->cs_exception[idx]);
+
+ if (cstack->cs_idx >= 0
+ && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
+ {
+ // Variables declared in the previous block can no longer be
+ // used.
+ leave_block(cstack);
+ enter_block(cstack);
+ }
+
// It's mandatory that the current exception is stored in the cstack
// so that it can be discarded at the next ":catch", ":finally", or
// ":endtry" or when the catch clause is left by a ":continue",
***************
*** 1930,1935 ****
--- 1940,1954 ----
*/
cleanup_conditionals(cstack, CSF_TRY, FALSE);
+ if (cstack->cs_idx >= 0
+ && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
+ {
+ // Variables declared in the previous block can no longer be
+ // used.
+ leave_block(cstack);
+ enter_block(cstack);
+ }
+
/*
* Make did_emsg, got_int, did_throw pending. If set, they overrule
* a pending ":continue", ":break", ":return", or ":finish". Then
*** ../vim-8.2.4498/src/testdir/test_vim9_script.vim 2022-02-17 19:44:04.275319369 +0000
--- src/testdir/test_vim9_script.vim 2022-03-03 15:08:36.151231046 +0000
***************
*** 763,768 ****
--- 763,792 ----
v9.CheckDefAndScriptSuccess(lines)
enddef
+ def Test_try_var_decl()
+ var lines =<< trim END
+ vim9script
+ try
+ var in_try = 1
+ assert_equal(1, get(s:, 'in_try', -1))
+ throw "getout"
+ catch
+ var in_catch = 2
+ assert_equal(-1, get(s:, 'in_try', -1))
+ assert_equal(2, get(s:, 'in_catch', -1))
+ finally
+ var in_finally = 3
+ assert_equal(-1, get(s:, 'in_try', -1))
+ assert_equal(-1, get(s:, 'in_catch', -1))
+ assert_equal(3, get(s:, 'in_finally', -1))
+ endtry
+ assert_equal(-1, get(s:, 'in_try', -1))
+ assert_equal(-1, get(s:, 'in_catch', -1))
+ assert_equal(-1, get(s:, 'in_finally', -1))
+ END
+ v9.CheckScriptSuccess(lines)
+ enddef
+
def Test_try_ends_in_return()
var lines =<< trim END
vim9script
*** ../vim-8.2.4498/src/version.c 2022-03-03 13:55:34.159276047 +0000
--- src/version.c 2022-03-03 15:08:02.395367364 +0000
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 4499,
/**/
--
hundred-and-one symptoms of being an internet addict:
151. You find yourself engaged to someone you've never actually met,
except through e-mail.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///