Patch 8.2.2543
Problem: Vim9: a return inside try/catch does not restore exception state
properly.
Solution: When there is no ":finally" jump to ":endtry". (closes #7882)
Files: src/vim9execute.c, src/testdir/test_vim9_script.vim
*** ../vim-8.2.2542/src/vim9execute.c 2021-02-21 21:32:38.301201176 +0100
--- src/vim9execute.c 2021-02-22 22:43:46.919967751 +0100
***************
*** 2517,2527 ****
trycmd = ((trycmd_T *)trystack->ga_data)
+ trystack->ga_len - 1;
if (trycmd != NULL
! && trycmd->tcd_frame_idx == ectx.ec_frame_idx
! && trycmd->tcd_finally_idx != 0)
{
! // jump to ":finally" once
! ectx.ec_iidx = trycmd->tcd_finally_idx;
trycmd->tcd_return = TRUE;
}
else
--- 2517,2529 ----
trycmd = ((trycmd_T *)trystack->ga_data)
+ trystack->ga_len - 1;
if (trycmd != NULL
! && trycmd->tcd_frame_idx == ectx.ec_frame_idx)
{
! // jump to ":finally" or ":endtry"
! if (trycmd->tcd_finally_idx != 0)
! ectx.ec_iidx = trycmd->tcd_finally_idx;
! else
! ectx.ec_iidx = trycmd->tcd_endtry_idx;
trycmd->tcd_return = TRUE;
}
else
*** ../vim-8.2.2542/src/testdir/test_vim9_script.vim 2021-02-21
21:32:38.301201176 +0100
--- src/testdir/test_vim9_script.vim 2021-02-22 22:39:26.769027006 +0100
***************
*** 589,594 ****
--- 589,606 ----
assert_equal(4, ReturnInFinally())
enddef
+ def Test_nocatch_return_in_try()
+ # return in try block returns normally
+ def ReturnInTry(): string
+ try
+ return '"some message"'
+ catch
+ endtry
+ return 'not reached'
+ enddef
+ exe 'echoerr ' .. ReturnInTry()
+ enddef
+
def Test_cnext_works_in_catch()
var lines =<< trim END
vim9script
*** ../vim-8.2.2542/src/version.c 2021-02-22 22:13:08.447640357 +0100
--- src/version.c 2021-02-22 22:32:45.646667031 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2543,
/**/
--
Lose weight, NEVER Diet again with
The "Invisible Weight Loss Patch"
(spam e-mail)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202102222147.11MLlOsZ3536703%40masaka.moolenaar.net.