delete('XimportRel3.vim')
enddef
+def Test_autoload_import_relative_autoload_dir()
+ mkdir('autoload', 'p')
+ var lines =<< trim END
+ vim9script
+ export def Bar()
+ g:called_bar = 'yes'
+ enddef
+ END
+ writefile(lines, 'autoload/script.vim')
+
+ lines =<< trim END
+ vim9script
+ import autoload './autoload/script.vim'
+ def Foo()
+ script.Bar()
+ enddef
+ Foo()
+ assert_equal('yes', g:called_bar)
+ END
+ v9.CheckScriptSuccess(lines)
+
+ unlet g:called_bar
+ delete('autoload', 'rf')
+enddef
+
func Test_import_in_diffexpr()
CheckExecutable diff
*p = NUL;
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);
+ if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
+ // "import autoload './dir/script.vim'" or
+ // "import autoload './autoload/script.vim'" - load script first
+ res = generate_SOURCE(cctx, import->imp_sid);
- // autoload script must be loaded later, access by the autoload
- // name. If a '(' follows it must be a function. Otherwise we
- // don't know, it can be "script.Func".
- if (cc == '(' || paren_follows_after_expr)
- res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
- else
- res = generate_AUTOLOAD(cctx, auto_name, &t_any);
- vim_free(auto_name);
- done = TRUE;
- }
- else if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
+ if (res == OK)
{
- // "import autoload './dir/script.vim'" - load script first
- res = generate_SOURCE(cctx, import->imp_sid);
- if (res == OK)
+ 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 a '(' follows it must be a function. Otherwise we
+ // don't know, it can be "script.Func".
+ if (cc == '(' || paren_follows_after_expr)
+ res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
+ else
+ res = generate_AUTOLOAD(cctx, auto_name, &t_any);
+ vim_free(auto_name);
+ done = TRUE;
+ }
+ else if (si->sn_import_autoload
+ && si->sn_state == SN_STATE_NOT_LOADED)
{
// If a '(' follows it must be a function. Otherwise we don't
// know, it can be "script.Func".
else
res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
import->imp_sid, &t_any);
+ done = TRUE;
+ }
+ else
+ {
+ idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
+ cctx, NULL, TRUE);
}
- done = TRUE;
- }
- else
- {
- idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
- cctx, NULL, TRUE);
}
+
*p = cc;
*end = p;
if (done)