To: vim_dev@googlegroups.com Subject: Patch 8.2.2503 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2503 Problem: Vim9: a caught error may leave something on the stack. Solution: Drop items from the stack if needed. (closes #7826) Files: src/vim9execute.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.2502/src/vim9execute.c 2021-02-11 21:19:30.522147936 +0100 --- src/vim9execute.c 2021-02-12 21:31:20.581143095 +0100 *************** *** 24,30 **** // Structure put on ec_trystack when ISN_TRY is encountered. typedef struct { ! int tcd_frame_idx; // ec_frame_idx when ISN_TRY was encountered int tcd_catch_idx; // instruction of the first catch int tcd_finally_idx; // instruction of the finally block int tcd_caught; // catch block entered --- 24,31 ---- // Structure put on ec_trystack when ISN_TRY is encountered. typedef struct { ! int tcd_frame_idx; // ec_frame_idx at ISN_TRY ! int tcd_stack_len; // size of ectx.ec_stack at ISN_TRY int tcd_catch_idx; // instruction of the first catch int tcd_finally_idx; // instruction of the finally block int tcd_caught; // catch block entered *************** *** 2561,2566 **** --- 2562,2568 ---- ++ectx.ec_trystack.ga_len; ++trylevel; trycmd->tcd_frame_idx = ectx.ec_frame_idx; + trycmd->tcd_stack_len = ectx.ec_stack.ga_len; trycmd->tcd_catch_idx = iptr->isn_arg.try.try_catch; trycmd->tcd_finally_idx = iptr->isn_arg.try.try_finally; trycmd->tcd_caught = FALSE; *************** *** 2632,2637 **** --- 2634,2645 ---- if (trycmd->tcd_return) goto func_return; + + while (ectx.ec_stack.ga_len > trycmd->tcd_stack_len) + { + --ectx.ec_stack.ga_len; + clear_tv(STACK_TV_BOT(0)); + } } } break; *** ../vim-8.2.2502/src/testdir/test_vim9_script.vim 2021-02-07 17:17:54.739378027 +0100 --- src/testdir/test_vim9_script.vim 2021-02-12 21:29:17.201466785 +0100 *************** *** 556,561 **** --- 556,571 ---- n = 411 endtry assert_equal(411, n) + + var counter = 0 + for i in range(4) + try + eval [][0] + catch + endtry + counter += 1 + endfor + assert_equal(4, counter) enddef def Test_cnext_works_in_catch() *** ../vim-8.2.2502/src/version.c 2021-02-12 19:48:47.888057588 +0100 --- src/version.c 2021-02-12 21:26:52.093960027 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2503, /**/ -- Q: How does a UNIX Guru pick up a girl? A: look; grep; which; eval; nice; uname; talk; date; /// 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 ///