changeset 22302:36e8e046c335 v8.2.1700

patch 8.2.1700: Vim9: try/catch causes wrong value to be returned Commit: https://github.com/vim/vim/commit/9939f57b7f1c17a0142ebfe4f9e0b634158593e1 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 16 22:29:52 2020 +0200 patch 8.2.1700: Vim9: try/catch causes wrong value to be returned Problem: Vim9: try/catch causes wrong value to be returned. Solution: Reset tcd_return. (closes https://github.com/vim/vim/issues/6964)
author Bram Moolenaar <Bram@vim.org>
date Wed, 16 Sep 2020 22:30:03 +0200
parents 3014f6ccad32
children 4ce3906e5997
files src/testdir/test_vim9_script.vim src/version.c src/vim9execute.c
diffstat 3 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1169,6 +1169,26 @@ def Test_try_catch_nested()
   assert_equal('finally', g:in_finally)
 enddef
 
+def TryOne(): number
+  try
+    return 0
+  catch
+  endtry
+  return 0
+enddef
+
+def TryTwo(n: number): string
+  try
+    let x = {}
+  catch
+  endtry
+  return 'text'
+enddef
+
+def Test_try_catch_twice()
+  assert_equal('text', TryOne()->TryTwo())
+enddef
+
 def Test_try_catch_match()
   let seq = 'a'
   try
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1700,
+/**/
     1699,
 /**/
     1698,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1922,6 +1922,7 @@ call_def_function(
 		    trycmd->tcd_catch_idx = iptr->isn_arg.try.try_catch;
 		    trycmd->tcd_finally_idx = iptr->isn_arg.try.try_finally;
 		    trycmd->tcd_caught = FALSE;
+		    trycmd->tcd_return = FALSE;
 		}
 		break;