To: vim_dev@googlegroups.com Subject: Patch 8.2.4006 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4006 Problem: Vim9: crash when declaring variable on the command line. Solution: Use a temporary type list. (closes #9474) Files: src/eval.c, src/testdir/test_vim9_assign.vim *** ../vim-8.2.4005/src/eval.c 2022-01-04 21:30:43.533800364 +0000 --- src/eval.c 2022-01-05 10:15:52.740530729 +0000 *************** *** 889,896 **** } if (*p == ':') { ! scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); ! char_u *tp = skipwhite(p + 1); if (tp == p + 1 && !quiet) { --- 889,897 ---- } if (*p == ':') { ! garray_T tmp_type_list; ! garray_T *type_list; ! char_u *tp = skipwhite(p + 1); if (tp == p + 1 && !quiet) { *************** *** 898,908 **** return NULL; } // parse the type after the name ! lp->ll_type = parse_type(&tp, &si->sn_type_list, !quiet); if (lp->ll_type == NULL && !quiet) return NULL; lp->ll_name_end = tp; } } } --- 899,924 ---- return NULL; } + if (SCRIPT_ID_VALID(current_sctx.sc_sid)) + type_list = &SCRIPT_ITEM(current_sctx.sc_sid)->sn_type_list; + else + { + type_list = &tmp_type_list; + ga_init2(type_list, sizeof(type_T), 10); + } + // parse the type after the name ! lp->ll_type = parse_type(&tp, type_list, !quiet); if (lp->ll_type == NULL && !quiet) return NULL; lp->ll_name_end = tp; + + // drop the type when not in a script + if (type_list == &tmp_type_list) + { + lp->ll_type = NULL; + clear_type_list(type_list); + } } } } *** ../vim-8.2.4005/src/testdir/test_vim9_assign.vim 2022-01-04 15:16:57.883864877 +0000 --- src/testdir/test_vim9_assign.vim 2022-01-05 10:14:48.800726141 +0000 *************** *** 2,7 **** --- 2,8 ---- source check.vim source vim9.vim + source term_util.vim let s:appendToMe = 'xxx' let s:addToMe = 111 *************** *** 2281,2286 **** --- 2282,2304 ---- delete('Xtestscript') enddef + func Test_declare_command_line() + CheckRunVimInTerminal + call Run_Test_declare_command_line() + endfunc + + def Run_Test_declare_command_line() + # On the command line the type is parsed but not used. + # To get rid of the script context have to run this in another Vim instance. + var buf = RunVimInTerminal('', {'rows': 6}) + term_sendkeys(buf, ":vim9 var abc: list> = [ [1, 2, 3], [4, 5, 6] ]\") + TermWait(buf) + term_sendkeys(buf, ":echo abc\") + TermWait(buf) + WaitForAssert(() => assert_match('\[\[1, 2, 3\], \[4, 5, 6\]\]', term_getline(buf, 6))) + StopVimInTerminal(buf) + enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.4005/src/version.c 2022-01-04 21:30:43.545800339 +0000 --- src/version.c 2022-01-05 10:16:07.152486678 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4006, /**/ -- hundred-and-one symptoms of being an internet addict: 223. You set up a web-cam as your home's security system. /// 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 ///