To: vim_dev@googlegroups.com Subject: Patch 8.2.3099 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3099 Problem: Vim9: missing catch/finally not reported at script level. Solution: Give an error. (closes #8487) Files: src/structs.h, src/ex_eval.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.3098/src/structs.h 2021-07-03 18:56:49.917634884 +0200 --- src/structs.h 2021-07-04 14:25:52.534221303 +0200 *************** *** 936,948 **** # define CSF_TRY 0x0100 // is a ":try" # define CSF_FINALLY 0x0200 // ":finally" has been passed ! # define CSF_THROWN 0x0400 // exception thrown to this try conditional ! # define CSF_CAUGHT 0x0800 // exception caught by this try conditional ! # define CSF_SILENT 0x1000 // "emsg_silent" reset by ":try" // Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset // (an ":if"), and CSF_SILENT is only used when CSF_TRY is set. // ! #define CSF_FUNC_DEF 0x2000 // a function was defined in this block /* * What's pending for being reactivated at the ":endtry" of this try --- 936,949 ---- # define CSF_TRY 0x0100 // is a ":try" # define CSF_FINALLY 0x0200 // ":finally" has been passed ! # define CSF_CATCH 0x0400 // ":catch" has been seen ! # define CSF_THROWN 0x0800 // exception thrown to this try conditional ! # define CSF_CAUGHT 0x1000 // exception caught by this try conditional ! # define CSF_SILENT 0x2000 // "emsg_silent" reset by ":try" // Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset // (an ":if"), and CSF_SILENT is only used when CSF_TRY is set. // ! #define CSF_FUNC_DEF 0x4000 // a function was defined in this block /* * What's pending for being reactivated at the ":endtry" of this try *** ../vim-8.2.3098/src/ex_eval.c 2021-04-05 22:27:33.402532604 +0200 --- src/ex_eval.c 2021-07-04 14:38:21.148335043 +0200 *************** *** 1670,1675 **** --- 1670,1677 ---- for (idx = cstack->cs_idx; idx > 0; --idx) if (cstack->cs_flags[idx] & CSF_TRY) break; + if (cstack->cs_flags[idx] & CSF_TRY) + cstack->cs_flags[idx] |= CSF_CATCH; if (cstack->cs_flags[idx] & CSF_FINALLY) { // Give up for a ":catch" after ":finally" and ignore it. *************** *** 1963,1970 **** * made inactive by a ":continue", ":break", ":return", or ":finish" in * the finally clause. The latter case need not be tested since then * anything pending has already been discarded. */ ! skip = did_emsg || got_int || did_throw || ! !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { --- 1965,1972 ---- * made inactive by a ":continue", ":break", ":return", or ":finish" in * the finally clause. The latter case need not be tested since then * anything pending has already been discarded. */ ! skip = did_emsg || got_int || did_throw ! || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { *************** *** 1992,1997 **** --- 1994,2007 ---- { idx = cstack->cs_idx; + if (in_vim9script() + && (cstack->cs_flags[idx] & (CSF_CATCH|CSF_FINALLY)) == 0) + { + // try/endtry without any catch or finally: give an error and + // continue. + eap->errmsg = _(e_missing_catch_or_finally); + } + /* * If we stopped with the exception currently being thrown at this * try conditional since we didn't know that it doesn't have *** ../vim-8.2.3098/src/testdir/test_vim9_script.vim 2021-06-30 20:39:11.366130953 +0200 --- src/testdir/test_vim9_script.vim 2021-07-04 14:39:33.584169610 +0200 *************** *** 603,608 **** --- 603,617 ---- CheckScriptSuccess(lines) assert_match('E808: Number or Float required', g:caught) unlet g:caught + + # missing catch and/or finally + lines =<< trim END + vim9script + try + echo 'something' + endtry + END + CheckScriptFailure(lines, 'E1032:') enddef def Test_try_in_catch() *** ../vim-8.2.3098/src/version.c 2021-07-04 14:00:52.133474925 +0200 --- src/version.c 2021-07-04 14:44:40.083484923 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3099, /**/ -- From "know your smileys": :-) Funny |-) Funny Oriental (-: Funny Australian /// 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 ///