summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-12-20 10:55:35 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-20 10:55:35 +0000
commit003312b1d2ee2f4922f473b8bf50af6663c0efac (patch)
tree2a1c6930d3f9e0906210b1262e0843640d9249a0
parent2f9f4ccfc8f1d4a56761dc1cc1e9e20190a72c74 (diff)
downloadvim-git-8.2.3858.tar.gz
patch 8.2.3858: Vim9: not enough testsv8.2.3858
Problem: Vim9: not enough tests. Solution: Add tests for :try/:catch and :redir. Add missing type check.
-rw-r--r--src/testdir/test_vim9_cmd.vim17
-rw-r--r--src/testdir/test_vim9_script.vim40
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c11
4 files changed, 63 insertions, 7 deletions
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
index 6e01d9975..2d86b6ba3 100644
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1558,6 +1558,23 @@ def Test_redir_to_var()
redir END
END
CheckDefFailure(lines, 'E1141:')
+
+ lines =<< trim END
+ var text: string
+ redir => text
+ echo 'hello'
+ redir > Xfile
+ redir END
+ END
+ CheckDefFailure(lines, 'E1185:')
+
+ lines =<< trim END
+ var text: number
+ redir => text
+ echo 'hello'
+ redir END
+ END
+ CheckDefFailure(lines, 'E1012:')
enddef
def Test_echo_void()
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index c9ceccf0d..af80935ab 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -611,15 +611,49 @@ def Test_try_catch_throw()
# no requirement for spaces before |
try|echo 0|catch|endtry
+ # return in try with finally
+ def ReturnInTry(): number
+ var ret = 4
+ try
+ return ret
+ catch /this/
+ return -1
+ catch /that/
+ return -1
+ finally
+ # changing ret has no effect
+ ret = 7
+ endtry
+ return -2
+ enddef
+ assert_equal(4, ReturnInTry())
+
+ # return in catch with finally
+ def ReturnInCatch(): number
+ var ret = 5
+ try
+ throw 'getout'
+ return -1
+ catch /getout/
+ # ret is evaluated here
+ return ret
+ finally
+ # changing ret later has no effect
+ ret = -3
+ endtry
+ return -2
+ enddef
+ assert_equal(5, ReturnInCatch())
+
# return in finally after empty catch
def ReturnInFinally(): number
try
finally
- return 4
+ return 6
endtry
- return 2
+ return -1
enddef
- assert_equal(4, ReturnInFinally())
+ assert_equal(6, ReturnInFinally())
var lines =<< trim END
vim9script
diff --git a/src/version.c b/src/version.c
index b3121d15d..a7f372dd6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3858,
+/**/
3857,
/**/
3856,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8ef1faf3a..2b27f514c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8651,7 +8651,7 @@ compile_endblock(cctx_T *cctx)
}
/*
- * compile "try"
+ * Compile "try".
* Creates a new scope for the try-endtry, pointing to the first catch and
* finally.
* Creates another scope for the "try" block itself.
@@ -8722,7 +8722,7 @@ compile_try(char_u *arg, cctx_T *cctx)
}
/*
- * compile "catch {expr}"
+ * Compile "catch {expr}".
*/
static char_u *
compile_catch(char_u *arg, cctx_T *cctx UNUSED)
@@ -9477,8 +9477,8 @@ compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
static char_u *
compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
{
- char_u *arg = eap->arg;
- lhs_T *lhs = &cctx->ctx_redir_lhs;
+ char_u *arg = eap->arg;
+ lhs_T *lhs = &cctx->ctx_redir_lhs;
if (lhs->lhs_name != NULL)
{
@@ -9534,6 +9534,9 @@ compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
if (compile_assign_lhs(arg, lhs, CMD_redir,
FALSE, FALSE, 1, cctx) == FAIL)
return NULL;
+ if (need_type(&t_string, lhs->lhs_member_type,
+ -1, 0, cctx, FALSE, FALSE) == FAIL)
+ return NULL;
generate_instr(cctx, ISN_REDIRSTART);
lhs->lhs_append = append;
if (lhs->lhs_has_index)