1
0
forked from aniani/vim

patch 9.0.0744: in script in autoload dir exported variable is not found

Problem:    In script in autoload dir exported variable is not found. (Doug
            Kearns)
Solution:   Find the variable with the "script#" prefix. (closes #11361)
This commit is contained in:
Bram Moolenaar
2022-10-13 17:47:42 +01:00
parent 66b8d2a89e
commit 6c4d4a6444
3 changed files with 29 additions and 5 deletions

View File

@@ -3160,18 +3160,20 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
// When using "vim9script autoload" script-local items are prefixed but can
// be used with s:name.
if (SCRIPT_ID_VALID(current_sctx.sc_sid)
&& name[0] == 's' && name[1] == ':')
&& (in_vim9script() || (name[0] == 's' && name[1] == ':')))
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
if (si->sn_autoload_prefix != NULL)
{
char_u *auto_name = concat_str(si->sn_autoload_prefix, name + 2);
char_u *base_name = (name[0] == 's' && name[1] == ':')
? name + 2 : name;
char_u *auto_name = concat_str(si->sn_autoload_prefix, base_name);
if (auto_name != NULL)
{
ht = &globvarht;
ret = find_var_in_ht(ht, *name, auto_name, TRUE);
ret = find_var_in_ht(ht, 'g', auto_name, TRUE);
vim_free(auto_name);
if (ret != NULL)
{

View File

@@ -1218,6 +1218,26 @@ def Test_autoload_import_deleted()
delete('Xa.vim')
enddef
def Test_autoload_import_using_const()
mkdir('Xdir/autoload', 'pR')
var lines =<< trim END
vim9script
export const FOO = 42
echomsg FOO
END
writefile(lines, 'Xdir/autoload/exp.vim')
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdir'
lines =<< trim END
vim9script
import autoload 'exp.vim'
assert_equal(42, exp.FOO)
END
v9.CheckScriptSuccess(lines)
&rtp = save_rtp
enddef
func Test_import_in_diffexpr()
CheckExecutable diff
@@ -2570,7 +2590,7 @@ def Test_vim9script_autoload_duplicate()
enddef
END
writefile(lines, 'Xdupdir/autoload/dup4func.vim')
assert_fails('source Xdupdir/autoload/dup4func.vim', 'E707:')
assert_fails('source Xdupdir/autoload/dup4func.vim', 'E1041:')
lines =<< trim END
vim9script

View File

@@ -699,6 +699,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
744,
/**/
743,
/**/