mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.0992: Vim9: crash when using :import in the Vim command
Problem: Vim9: crash when using :import in the Vim command. Solution: Give an error when using :import outside of a script. (closes #6271)
This commit is contained in:
parent
0fe937fd86
commit
101f4810e2
@ -107,16 +107,18 @@ func RunVimInTerminal(arguments, options)
|
|||||||
|
|
||||||
call TermWait(buf)
|
call TermWait(buf)
|
||||||
|
|
||||||
" Wait for "All" or "Top" of the ruler to be shown in the last line or in
|
if get(a:options, 'wait_for_ruler', 1)
|
||||||
" the status line of the last window. This can be quite slow (e.g. when
|
" Wait for "All" or "Top" of the ruler to be shown in the last line or in
|
||||||
" using valgrind).
|
" the status line of the last window. This can be quite slow (e.g. when
|
||||||
" If it fails then show the terminal contents for debugging.
|
" using valgrind).
|
||||||
try
|
" If it fails then show the terminal contents for debugging.
|
||||||
call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1})
|
try
|
||||||
catch /timed out after/
|
call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1})
|
||||||
let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
|
catch /timed out after/
|
||||||
call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
|
let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
|
||||||
endtry
|
call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
|
|
||||||
" Starting a terminal to run Vim is always considered flaky.
|
" Starting a terminal to run Vim is always considered flaky.
|
||||||
let g:test_is_flaky = 1
|
let g:test_is_flaky = 1
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
" Test various aspects of the Vim9 script language.
|
" Test various aspects of the Vim9 script language.
|
||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
|
source term_util.vim
|
||||||
source view_util.vim
|
source view_util.vim
|
||||||
source vim9.vim
|
source vim9.vim
|
||||||
|
|
||||||
@ -777,6 +778,25 @@ def Test_vim9script_fails()
|
|||||||
assert_fails('export something', 'E1043')
|
assert_fails('export something', 'E1043')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_import_fails_without_script()
|
||||||
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
let export =<< trim END
|
||||||
|
vim9script
|
||||||
|
export def Foo(): number
|
||||||
|
return 0
|
||||||
|
enddef
|
||||||
|
END
|
||||||
|
writefile(export, 'Xexport.vim')
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal('-c "import Foo from ''./Xexport.vim''"', #{
|
||||||
|
rows: 6, wait_for_ruler: 0})
|
||||||
|
WaitForAssert({-> assert_match('^E1094:', term_getline(buf, 5))})
|
||||||
|
|
||||||
|
delete('Xexport.vim')
|
||||||
|
StopVimInTerminal(buf)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_vim9script_reload_import()
|
def Test_vim9script_reload_import()
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
992,
|
||||||
/**/
|
/**/
|
||||||
991,
|
991,
|
||||||
/**/
|
/**/
|
||||||
|
@ -32,13 +32,14 @@ in_vim9script(void)
|
|||||||
void
|
void
|
||||||
ex_vim9script(exarg_T *eap)
|
ex_vim9script(exarg_T *eap)
|
||||||
{
|
{
|
||||||
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
scriptitem_T *si;
|
||||||
|
|
||||||
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
|
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
|
||||||
{
|
{
|
||||||
emsg(_("E1038: vim9script can only be used in a script"));
|
emsg(_("E1038: vim9script can only be used in a script"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
si = SCRIPT_ITEM(current_sctx.sc_sid);
|
||||||
if (si->sn_had_command)
|
if (si->sn_had_command)
|
||||||
{
|
{
|
||||||
emsg(_("E1039: vim9script must be the first command in a script"));
|
emsg(_("E1039: vim9script must be the first command in a script"));
|
||||||
@ -141,8 +142,15 @@ free_imports(int sid)
|
|||||||
void
|
void
|
||||||
ex_import(exarg_T *eap)
|
ex_import(exarg_T *eap)
|
||||||
{
|
{
|
||||||
char_u *cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid, NULL);
|
char_u *cmd_end;
|
||||||
|
|
||||||
|
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
|
||||||
|
{
|
||||||
|
emsg(_("E1094: import can only be used in a script"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid, NULL);
|
||||||
if (cmd_end != NULL)
|
if (cmd_end != NULL)
|
||||||
eap->nextcmd = check_nextcmd(cmd_end);
|
eap->nextcmd = check_nextcmd(cmd_end);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user