mirror of
https://github.com/vim/vim.git
synced 2025-09-04 21:33:48 -04:00
patch 8.2.4072: Vim9: compiling function fails when autoload is not loaded
Problem: Vim9: compiling function fails when autoload script is not loaded yet. Solution: Depend on runtime loading.
This commit is contained in:
parent
53c296112e
commit
d041f4208b
@ -1218,6 +1218,42 @@ def Test_vim9script_autoload_call()
|
|||||||
&rtp = save_rtp
|
&rtp = save_rtp
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_import_autoload_postponed()
|
||||||
|
mkdir('Xdir/autoload', 'p')
|
||||||
|
var save_rtp = &rtp
|
||||||
|
exe 'set rtp^=' .. getcwd() .. '/Xdir'
|
||||||
|
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script autoload
|
||||||
|
|
||||||
|
g:loaded_postponed = 'true'
|
||||||
|
export var variable = 'bla'
|
||||||
|
export def Function(): string
|
||||||
|
return 'bla'
|
||||||
|
enddef
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xdir/autoload/postponed.vim')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
import autoload 'postponed.vim'
|
||||||
|
def Tryit()
|
||||||
|
echo postponed.variable
|
||||||
|
echo postponed.Function()
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
assert_false(exists('g:loaded_postponed'))
|
||||||
|
CheckScriptSuccess(lines + ['Tryit()'])
|
||||||
|
assert_equal('true', g:loaded_postponed)
|
||||||
|
|
||||||
|
unlet g:loaded_postponed
|
||||||
|
delete('Xdir', 'rf')
|
||||||
|
&rtp = save_rtp
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_autoload_mapping()
|
def Test_autoload_mapping()
|
||||||
mkdir('Xdir/autoload', 'p')
|
mkdir('Xdir/autoload', 'p')
|
||||||
var save_rtp = &rtp
|
var save_rtp = &rtp
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
4072,
|
||||||
/**/
|
/**/
|
||||||
4071,
|
4071,
|
||||||
/**/
|
/**/
|
||||||
|
@ -2227,6 +2227,16 @@ exec_instructions(ectx_T *ectx)
|
|||||||
}
|
}
|
||||||
di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
|
di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
|
||||||
|
|
||||||
|
if (di == NULL && ht == get_globvar_ht())
|
||||||
|
{
|
||||||
|
// may need to load autoload script
|
||||||
|
if (script_autoload(iptr->isn_arg.string, FALSE))
|
||||||
|
di = find_var_in_ht(ht, 0,
|
||||||
|
iptr->isn_arg.string, TRUE);
|
||||||
|
if (did_emsg)
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
|
|
||||||
if (di == NULL)
|
if (di == NULL)
|
||||||
{
|
{
|
||||||
SOURCING_LNUM = iptr->isn_lnum;
|
SOURCING_LNUM = iptr->isn_lnum;
|
||||||
|
@ -274,6 +274,8 @@ compile_load_scriptvar(
|
|||||||
int cc;
|
int cc;
|
||||||
ufunc_T *ufunc;
|
ufunc_T *ufunc;
|
||||||
type_T *type;
|
type_T *type;
|
||||||
|
int done = FALSE;
|
||||||
|
int res = OK;
|
||||||
|
|
||||||
// TODO: if this is an autoload import do something else.
|
// TODO: if this is an autoload import do something else.
|
||||||
// Need to lookup the member.
|
// Need to lookup the member.
|
||||||
@ -296,11 +298,31 @@ compile_load_scriptvar(
|
|||||||
cc = *p;
|
cc = *p;
|
||||||
*p = NUL;
|
*p = NUL;
|
||||||
|
|
||||||
idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
|
si = SCRIPT_ITEM(import->imp_sid);
|
||||||
|
if (si->sn_autoload_prefix != NULL
|
||||||
|
&& si->sn_state == SN_STATE_NOT_LOADED)
|
||||||
|
{
|
||||||
|
char_u *auto_name = concat_str(si->sn_autoload_prefix, exp_name);
|
||||||
|
|
||||||
|
// autoload script must be loaded later, access by the autoload
|
||||||
|
// name.
|
||||||
|
if (cc == '(')
|
||||||
|
res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
|
||||||
|
else
|
||||||
|
res = generate_LOAD(cctx, ISN_LOADG, 0, auto_name, &t_any);
|
||||||
|
vim_free(auto_name);
|
||||||
|
done = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
|
||||||
cctx, TRUE);
|
cctx, TRUE);
|
||||||
|
}
|
||||||
*p = cc;
|
*p = cc;
|
||||||
p = skipwhite(p);
|
p = skipwhite(p);
|
||||||
*end = p;
|
*end = p;
|
||||||
|
if (done)
|
||||||
|
return res;
|
||||||
|
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
{
|
{
|
||||||
|
@ -714,7 +714,6 @@ generate_PUSHBLOB(cctx_T *cctx, blob_T *blob)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate an ISN_PUSHFUNC instruction with name "name".
|
* Generate an ISN_PUSHFUNC instruction with name "name".
|
||||||
* Consumes "name".
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
|
generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
|
||||||
@ -727,7 +726,8 @@ generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
funcname = NULL;
|
funcname = NULL;
|
||||||
else if (*name == K_SPECIAL) // script-local
|
else if (*name == K_SPECIAL // script-local
|
||||||
|
|| vim_strchr(name, AUTOLOAD_CHAR) != NULL) // autoload
|
||||||
funcname = vim_strsave(name);
|
funcname = vim_strsave(name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -488,7 +488,16 @@ handle_import(
|
|||||||
// we need a scriptitem without loading the script
|
// we need a scriptitem without loading the script
|
||||||
sid = find_script_in_rtp(from_name);
|
sid = find_script_in_rtp(from_name);
|
||||||
vim_free(from_name);
|
vim_free(from_name);
|
||||||
res = SCRIPT_ID_VALID(sid) ? OK : FAIL;
|
if (SCRIPT_ID_VALID(sid))
|
||||||
|
{
|
||||||
|
scriptitem_T *si = SCRIPT_ITEM(sid);
|
||||||
|
|
||||||
|
if (si->sn_autoload_prefix == NULL)
|
||||||
|
si->sn_autoload_prefix = get_autoload_prefix(si);
|
||||||
|
res = OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
res = FAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user