To: vim_dev@googlegroups.com Subject: Patch 8.2.1230 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1230 Problem: Vim9: list index error not caught by try/catch. Solution: Do not bail out if an error is inside try/catch. (closes #6462) Files: src/vim9execute.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1229/src/vim9execute.c 2020-07-15 22:38:52.681292060 +0200 --- src/vim9execute.c 2020-07-17 21:52:21.769799868 +0200 *************** *** 1065,1070 **** --- 1065,1072 ---- if (di == NULL) { semsg(_(e_undefvar), name); + if (trylevel > 0) + continue; goto failed; } else *************** *** 1786,1791 **** --- 1788,1794 ---- --trystack->ga_len; --trylevel; + ectx.ec_in_catch = FALSE; trycmd = ((trycmd_T *)trystack->ga_data) + trystack->ga_len; if (trycmd->tcd_caught && current_exception != NULL) *************** *** 2084,2090 **** case EXPR_DIV: f1 = f1 / f2; break; case EXPR_SUB: f1 = f1 - f2; break; case EXPR_ADD: f1 = f1 + f2; break; ! default: emsg(_(e_modulus)); goto failed; } clear_tv(tv1); clear_tv(tv2); --- 2087,2096 ---- case EXPR_DIV: f1 = f1 / f2; break; case EXPR_SUB: f1 = f1 - f2; break; case EXPR_ADD: f1 = f1 + f2; break; ! default: emsg(_(e_modulus)); ! if (trylevel > 0) ! continue; ! goto failed; } clear_tv(tv1); clear_tv(tv2); *************** *** 2138,2143 **** --- 2144,2151 ---- if (tv->v_type != VAR_LIST) { emsg(_(e_listreq)); + if (trylevel > 0) + continue; goto failed; } list = tv->vval.v_list; *************** *** 2146,2151 **** --- 2154,2161 ---- if (tv->v_type != VAR_NUMBER) { emsg(_(e_number_exp)); + if (trylevel > 0) + continue; goto failed; } n = tv->vval.v_number; *************** *** 2153,2163 **** if ((li = list_find(list, n)) == NULL) { semsg(_(e_listidx), n); goto failed; } --ectx.ec_stack.ga_len; // Clear the list after getting the item, to avoid that it ! // make the item invalid. tv = STACK_TV_BOT(-1); temp_tv = *tv; copy_tv(&li->li_tv, tv); --- 2163,2175 ---- if ((li = list_find(list, n)) == NULL) { semsg(_(e_listidx), n); + if (trylevel > 0) + continue; goto failed; } --ectx.ec_stack.ga_len; // Clear the list after getting the item, to avoid that it ! // makes the item invalid. tv = STACK_TV_BOT(-1); temp_tv = *tv; copy_tv(&li->li_tv, tv); *************** *** 2226,2231 **** --- 2238,2245 ---- if ((di = dict_find(dict, key, -1)) == NULL) { semsg(_(e_dictkey), key); + if (trylevel > 0) + continue; goto failed; } clear_tv(tv); *** ../vim-8.2.1229/src/testdir/test_vim9_script.vim 2020-07-17 20:35:00.857574357 +0200 --- src/testdir/test_vim9_script.vim 2020-07-17 22:05:18.419989590 +0200 *************** *** 509,514 **** --- 509,551 ---- add(l, '3') endtry # comment assert_equal(['1', 'wrong', '3'], l) + + let n: number + try + n = l[3] + catch /E684:/ + n = 99 + endtry + assert_equal(99, n) + + try + n = g:astring[3] + catch /E714:/ + n = 77 + endtry + assert_equal(77, n) + + try + n = l[g:astring] + catch /E39:/ + n = 77 + endtry + assert_equal(77, n) + + try + n = s:does_not_exist + catch /E121:/ + n = 121 + endtry + assert_equal(121, n) + + let d = #{one: 1} + try + n = d[g:astring] + catch /E716:/ + n = 222 + endtry + assert_equal(222, n) enddef def ThrowFromDef() *** ../vim-8.2.1229/src/version.c 2020-07-17 20:47:47.640033591 +0200 --- src/version.c 2020-07-17 21:11:07.432288581 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1230, /**/ -- My sister Cecilia opened a computer store in Hawaii. She sells C shells by the seashore. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///