To: vim_dev@googlegroups.com Subject: Patch 8.2.2021 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2021 Problem: Vim9: get E1099 when autocommand resets did_emsg. Solution: Add did_emsg_cumul. (closes #7336) Files: src/globals.h, src/ex_docmd.c, src/vim9execute.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.2020/src/globals.h 2020-11-04 11:03:08.372891857 +0100 --- src/globals.h 2020-11-20 19:11:49.968042865 +0100 *************** *** 230,235 **** --- 230,237 ---- EXTERN int did_emsg; // set by emsg() when the message // is displayed or thrown #ifdef FEAT_EVAL + EXTERN int did_emsg_cumul; // cumulative did_emsg, increased + // when did_emsg is reset. EXTERN int called_vim_beep; // set if vim_beep() is called EXTERN int did_uncaught_emsg; // emsg() was called and did not // cause an exception *** ../vim-8.2.2020/src/ex_docmd.c 2020-11-12 14:20:32.021927293 +0100 --- src/ex_docmd.c 2020-11-20 19:14:38.799505782 +0100 *************** *** 747,752 **** --- 747,755 ---- * cancel the whole command line, and any if/endif or loop. * If force_abort is set, we cancel everything. */ + #ifdef FEAT_EVAL + did_emsg_cumul += did_emsg; + #endif did_emsg = FALSE; /* *************** *** 778,784 **** --- 781,792 ---- && !(getline_is_func && func_has_abort(real_cookie)) #endif ) + { + #ifdef FEAT_EVAL + did_emsg_cumul += did_emsg; + #endif did_emsg = FALSE; + } /* * 1. If repeating a line in a loop, get a line from lines_ga. *************** *** 1026,1032 **** --- 1034,1043 ---- if (did_emsg && !force_abort && getline_equal(fgetline, cookie, get_func_line) && !func_has_abort(real_cookie)) + { + // did_emsg_cumul is not set here did_emsg = FALSE; + } if (cstack.cs_looplevel > 0) { *** ../vim-8.2.2020/src/vim9execute.c 2020-11-17 18:23:15.519278866 +0100 --- src/vim9execute.c 2020-11-20 19:24:41.249551834 +0100 *************** *** 833,839 **** int defcount = ufunc->uf_args.ga_len - argc; sctx_T save_current_sctx = current_sctx; int breakcheck_count = 0; ! int did_emsg_before = did_emsg; int save_suppress_errthrow = suppress_errthrow; msglist_T **saved_msg_list = NULL; msglist_T *private_msg_list = NULL; --- 833,839 ---- int defcount = ufunc->uf_args.ga_len - argc; sctx_T save_current_sctx = current_sctx; int breakcheck_count = 0; ! int did_emsg_before = did_emsg_cumul + did_emsg; int save_suppress_errthrow = suppress_errthrow; msglist_T **saved_msg_list = NULL; msglist_T *private_msg_list = NULL; *************** *** 859,865 **** || (ufunc->uf_def_status == UF_TO_BE_COMPILED && compile_def_function(ufunc, FALSE, NULL) == FAIL)) { ! if (did_emsg == did_emsg_before) semsg(_(e_function_is_not_compiled_str), printable_func_name(ufunc)); return FAIL; --- 859,865 ---- || (ufunc->uf_def_status == UF_TO_BE_COMPILED && compile_def_function(ufunc, FALSE, NULL) == FAIL)) { ! if (did_emsg_cumul + did_emsg == did_emsg_before) semsg(_(e_function_is_not_compiled_str), printable_func_name(ufunc)); return FAIL; *************** *** 1086,1098 **** // execute Ex command line case ISN_EXEC: { - int save_did_emsg = did_emsg; - SOURCING_LNUM = iptr->isn_lnum; do_cmdline_cmd(iptr->isn_arg.string); ! // do_cmdline_cmd() will reset did_emsg, but we want to ! // keep track of the count to compare with did_emsg_before. ! did_emsg += save_did_emsg; } break; --- 1086,1095 ---- // execute Ex command line case ISN_EXEC: { SOURCING_LNUM = iptr->isn_lnum; do_cmdline_cmd(iptr->isn_arg.string); ! if (did_emsg) ! goto on_error; } break; *************** *** 1211,1216 **** --- 1208,1215 ---- { SOURCING_LNUM = iptr->isn_lnum; do_cmdline_cmd((char_u *)ga.ga_data); + if (did_emsg) + goto on_error; } else { *************** *** 2894,2900 **** on_error: // If "emsg_silent" is set then ignore the error. ! if (did_emsg == did_emsg_before && emsg_silent) continue; // If we are not inside a try-catch started here, abort execution. --- 2893,2899 ---- on_error: // If "emsg_silent" is set then ignore the error. ! if (did_emsg_cumul + did_emsg == did_emsg_before && emsg_silent) continue; // If we are not inside a try-catch started here, abort execution. *************** *** 2952,2958 **** // Not sure if this is necessary. suppress_errthrow = save_suppress_errthrow; ! if (ret != OK && did_emsg == did_emsg_before) semsg(_(e_unknown_error_while_executing_str), printable_func_name(ufunc)); funcdepth_restore(orig_funcdepth); --- 2951,2957 ---- // Not sure if this is necessary. suppress_errthrow = save_suppress_errthrow; ! if (ret != OK && did_emsg_cumul + did_emsg == did_emsg_before) semsg(_(e_unknown_error_while_executing_str), printable_func_name(ufunc)); funcdepth_restore(orig_funcdepth); *** ../vim-8.2.2020/src/testdir/test_vim9_func.vim 2020-11-19 21:47:52.722076508 +0100 --- src/testdir/test_vim9_func.vim 2020-11-20 19:22:29.445966471 +0100 *************** *** 1704,1708 **** --- 1704,1722 ---- CheckScriptSuccess(lines) enddef + def Test_reset_did_emsg() + var lines =<< trim END + @s = 'blah' + au BufWinLeave * # + def Func() + var winid = popup_create('popup', {}) + exe '*s' + popup_close(winid) + enddef + Func() + END + CheckScriptFailure(lines, 'E492:', 8) + enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.2020/src/version.c 2020-11-20 18:59:14.470192932 +0100 --- src/version.c 2020-11-20 19:26:23.581268712 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2021, /**/ -- Facepalm statement #1: "I'm going to New York tomorrow, hopefully I have time to visit the White House" /// 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 ///