changeset 30819:d50d32026617 v9.0.0744

patch 9.0.0744: in script in autoload dir exported variable is not found Commit: https://github.com/vim/vim/commit/6c4d4a64449ea225b1a568f5517e309b2054b490 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 13 17:47:42 2022 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Oct 2022 19:00:06 +0200
parents a4597b441141
children 17010fc3d4d9
files src/evalvars.c src/testdir/test_vim9_import.vim src/version.c
diffstat 3 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -1326,7 +1326,7 @@ skip_var_list(
 	}
 	return p + 1;
     }
- 
+
     return skip_var_one(arg, include_type);
 }
 
@@ -3160,18 +3160,20 @@ find_var(char_u *name, hashtab_T **htp, 
     // 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)
 		{
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -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
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    744,
+/**/
     743,
 /**/
     742,