mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.4006: Vim9: crash when declaring variable on the command line
Problem: Vim9: crash when declaring variable on the command line. Solution: Use a temporary type list. (closes #9474)
This commit is contained in:
20
src/eval.c
20
src/eval.c
@@ -889,7 +889,8 @@ get_lval(
|
|||||||
}
|
}
|
||||||
if (*p == ':')
|
if (*p == ':')
|
||||||
{
|
{
|
||||||
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
garray_T tmp_type_list;
|
||||||
|
garray_T *type_list;
|
||||||
char_u *tp = skipwhite(p + 1);
|
char_u *tp = skipwhite(p + 1);
|
||||||
|
|
||||||
if (tp == p + 1 && !quiet)
|
if (tp == p + 1 && !quiet)
|
||||||
@@ -898,11 +899,26 @@ get_lval(
|
|||||||
return NULL;
|
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
|
// parse the type after the name
|
||||||
lp->ll_type = parse_type(&tp, &si->sn_type_list, !quiet);
|
lp->ll_type = parse_type(&tp, type_list, !quiet);
|
||||||
if (lp->ll_type == NULL && !quiet)
|
if (lp->ll_type == NULL && !quiet)
|
||||||
return NULL;
|
return NULL;
|
||||||
lp->ll_name_end = tp;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
source vim9.vim
|
source vim9.vim
|
||||||
|
source term_util.vim
|
||||||
|
|
||||||
let s:appendToMe = 'xxx'
|
let s:appendToMe = 'xxx'
|
||||||
let s:addToMe = 111
|
let s:addToMe = 111
|
||||||
@@ -2281,6 +2282,23 @@ def Test_abort_after_error()
|
|||||||
delete('Xtestscript')
|
delete('Xtestscript')
|
||||||
enddef
|
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<list<number>> = [ [1, 2, 3], [4, 5, 6] ]\<CR>")
|
||||||
|
TermWait(buf)
|
||||||
|
term_sendkeys(buf, ":echo abc\<CR>")
|
||||||
|
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: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4006,
|
||||||
/**/
|
/**/
|
||||||
4005,
|
4005,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user