To: vim_dev@googlegroups.com Subject: Patch 8.2.3858 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3858 Problem: Vim9: not enough tests. Solution: Add tests for :try/:catch and :redir. Add missing type check. Files: src/vim9compile.c, src/testdir/test_vim9_script.vim, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.3857/src/vim9compile.c 2021-12-19 21:34:01.699292755 +0000 --- src/vim9compile.c 2021-12-20 10:52:32.569222697 +0000 *************** *** 8651,8657 **** } /* ! * 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. --- 8651,8657 ---- } /* ! * 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,8728 **** } /* ! * compile "catch {expr}" */ static char_u * compile_catch(char_u *arg, cctx_T *cctx UNUSED) --- 8722,8728 ---- } /* ! * Compile "catch {expr}". */ static char_u * compile_catch(char_u *arg, cctx_T *cctx UNUSED) *************** *** 9477,9484 **** 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; if (lhs->lhs_name != NULL) { --- 9477,9484 ---- 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; if (lhs->lhs_name != NULL) { *************** *** 9534,9539 **** --- 9534,9542 ---- 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) *** ../vim-8.2.3857/src/testdir/test_vim9_script.vim 2021-12-19 18:33:17.325954806 +0000 --- src/testdir/test_vim9_script.vim 2021-12-20 10:11:37.246229454 +0000 *************** *** 611,625 **** # no requirement for spaces before | try|echo 0|catch|endtry # return in finally after empty catch def ReturnInFinally(): number try finally ! return 4 endtry ! return 2 enddef ! assert_equal(4, ReturnInFinally()) var lines =<< trim END vim9script --- 611,659 ---- # 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 6 endtry ! return -1 enddef ! assert_equal(6, ReturnInFinally()) var lines =<< trim END vim9script *** ../vim-8.2.3857/src/testdir/test_vim9_cmd.vim 2021-12-19 18:33:17.321954811 +0000 --- src/testdir/test_vim9_cmd.vim 2021-12-20 10:52:52.233177254 +0000 *************** *** 1558,1563 **** --- 1558,1580 ---- 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() *** ../vim-8.2.3857/src/version.c 2021-12-20 09:36:20.101548272 +0000 --- src/version.c 2021-12-20 10:08:44.082588320 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3858, /**/ -- hundred-and-one symptoms of being an internet addict: 87. Everyone you know asks why your phone line is always busy ...and you tell them to send an e-mail. /// Bram Moolenaar -- Bram@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 ///