forked from aniani/vim
patch 8.2.1739: Vim9: crash when compiling a manually defined function
Problem: Vim9: crash when compiling a manually defined function. (Antony Scriven) Solution: Check that the script ID is positive. (closes #7012)
This commit is contained in:
@@ -2755,7 +2755,7 @@ def Test_vim9_autoload_error()
|
||||
exe 'set rtp^=' .. getcwd() .. '/Xruntime'
|
||||
call crash#func()
|
||||
call writefile(['ok'], 'Xdidit')
|
||||
qall
|
||||
qall!
|
||||
END
|
||||
writefile(lines, 'Xscript')
|
||||
RunVim([], [], '-S Xscript')
|
||||
@@ -2817,7 +2817,7 @@ enddef
|
||||
def Test_invalid_sid()
|
||||
assert_fails('func <SNR>1234_func', 'E123:')
|
||||
|
||||
if RunVim([], ['wq Xdidit'], '+"func <SNR>1_func"')
|
||||
if RunVim([], ['wq! Xdidit'], '+"func <SNR>1_func"')
|
||||
assert_equal([], readfile('Xdidit'))
|
||||
endif
|
||||
delete('Xdidit')
|
||||
@@ -2831,6 +2831,27 @@ def Test_unset_any_variable()
|
||||
CheckDefAndScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
def Test_define_func_at_command_line()
|
||||
# run in a separate Vim instance to avoid the script context
|
||||
let lines =<< trim END
|
||||
func CheckAndQuit()
|
||||
call assert_fails('call Afunc()', 'E117: Unknown function: Bfunc')
|
||||
call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd')
|
||||
endfunc
|
||||
END
|
||||
writefile([''], 'Xdidcmd')
|
||||
writefile(lines, 'XcallFunc')
|
||||
let buf = RunVimInTerminal('-S XcallFunc', #{rows: 6})
|
||||
# define Afunc() on the command line
|
||||
term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
|
||||
term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
|
||||
WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))})
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
delete('XcallFunc')
|
||||
delete('Xdidcmd')
|
||||
enddef
|
||||
|
||||
" Keep this last, it messes up highlighting.
|
||||
def Test_substitute_cmd()
|
||||
new
|
||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1739,
|
||||
/**/
|
||||
1738,
|
||||
/**/
|
||||
|
@@ -277,9 +277,12 @@ script_is_vim9()
|
||||
lookup_script(char_u *name, size_t len, int vim9script)
|
||||
{
|
||||
int cc;
|
||||
hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
|
||||
hashtab_T *ht;
|
||||
dictitem_T *di;
|
||||
|
||||
if (current_sctx.sc_sid <= 0)
|
||||
return FAIL;
|
||||
ht = &SCRIPT_VARS(current_sctx.sc_sid);
|
||||
if (vim9script && !script_is_vim9())
|
||||
return FAIL;
|
||||
cc = name[len];
|
||||
|
Reference in New Issue
Block a user