• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision576a69fc006683d352bcfa5510b9528407fff102 (tree)
Time2020-10-18 05:15:03
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.1859: Vim9: crash in unpack assignment

Commit: https://github.com/vim/vim/commit/352134bbfbff4831a3f6a3383d9e2d8660016243
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 17 22:04:08 2020 +0200

patch 8.2.1859: Vim9: crash in unpack assignment
Problem: Vim9: crash in unpack assignment.
Solution: Make sure an error message is turned into an exception.
(closes #7159)

Change Summary

Incremental Difference

diff -r b5d68d8a5187 -r 576a69fc0066 src/testdir/test_vim9_assign.vim
--- a/src/testdir/test_vim9_assign.vim Sat Oct 17 19:30:05 2020 +0200
+++ b/src/testdir/test_vim9_assign.vim Sat Oct 17 22:15:03 2020 +0200
@@ -622,6 +622,9 @@
622622 CheckDefExecFailure(['var x: number',
623623 'var y: number',
624624 '[x, y] = [1]'], 'E1093:')
625+ CheckDefExecFailure(['var x: string',
626+ 'var y: string',
627+ '[x, y] = ["x"]'], 'E1093:')
625628 CheckDefExecFailure(['var x: number',
626629 'var y: number',
627630 'var z: list<number>',
diff -r b5d68d8a5187 -r 576a69fc0066 src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Sat Oct 17 19:30:05 2020 +0200
+++ b/src/testdir/test_vim9_script.vim Sat Oct 17 22:15:03 2020 +0200
@@ -620,6 +620,7 @@
620620
621621 lines =<< trim END
622622 vim9script
623+ @r = ''
623624 def Func()
624625 throw @r
625626 enddef
@@ -2818,6 +2819,27 @@
28182819 CheckScriptFailure(lines, 'E121:', 6)
28192820 enddef
28202821
2822+def Test_catch_exception_in_callback()
2823+ var lines =<< trim END
2824+ vim9script
2825+ def Callback(...l: any)
2826+ try
2827+ var x: string
2828+ var y: string
2829+ # this error should be caught with CHECKLEN
2830+ [x, y] = ['']
2831+ catch
2832+ g:caught = 'yes'
2833+ endtry
2834+ enddef
2835+ popup_menu('popup', #{callback: Callback})
2836+ feedkeys("\r", 'xt')
2837+ END
2838+ CheckScriptSuccess(lines)
2839+
2840+ unlet g:caught
2841+enddef
2842+
28212843 " Keep this last, it messes up highlighting.
28222844 def Test_substitute_cmd()
28232845 new
diff -r b5d68d8a5187 -r 576a69fc0066 src/version.c
--- a/src/version.c Sat Oct 17 19:30:05 2020 +0200
+++ b/src/version.c Sat Oct 17 22:15:03 2020 +0200
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 1859,
755+/**/
754756 1858,
755757 /**/
756758 1857,
diff -r b5d68d8a5187 -r 576a69fc0066 src/vim9execute.c
--- a/src/vim9execute.c Sat Oct 17 19:30:05 2020 +0200
+++ b/src/vim9execute.c Sat Oct 17 22:15:03 2020 +0200
@@ -830,6 +830,8 @@
830830 int breakcheck_count = 0;
831831 int called_emsg_before = called_emsg;
832832 int save_suppress_errthrow = suppress_errthrow;
833+ msglist_T **saved_msg_list = NULL;
834+ msglist_T *private_msg_list = NULL;
833835
834836 // Get pointer to item in the stack.
835837 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
@@ -982,6 +984,11 @@
982984 current_sctx = ufunc->uf_script_ctx;
983985 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
984986
987+ // Use a specific location for storing error messages to be converted to an
988+ // exception.
989+ saved_msg_list = msg_list;
990+ msg_list = &private_msg_list;
991+
985992 // Do turn errors into exceptions.
986993 suppress_errthrow = FALSE;
987994
@@ -2819,6 +2826,19 @@
28192826 estack_pop();
28202827 current_sctx = save_current_sctx;
28212828
2829+ if (*msg_list != NULL && saved_msg_list != NULL)
2830+ {
2831+ msglist_T **plist = saved_msg_list;
2832+
2833+ // Append entries from the current msg_list (uncaught exceptions) to
2834+ // the saved msg_list.
2835+ while (*plist != NULL)
2836+ plist = &(*plist)->next;
2837+
2838+ *plist = *msg_list;
2839+ }
2840+ msg_list = saved_msg_list;
2841+
28222842 failed_early:
28232843 // Free all local variables, but not arguments.
28242844 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
Show on old repository browser