]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable v8.2.4083
authorBram Moolenaar <Bram@vim.org>
Thu, 13 Jan 2022 20:18:56 +0000 (20:18 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 13 Jan 2022 20:18:56 +0000 (20:18 +0000)
Problem:    Vim9: no test for "vim9script autoload' and using script variable
            in the same script.
Solution:   Add a simple test.  Fix uncovered problem.

src/evalvars.c
src/testdir/test_vim9_import.vim
src/version.c

index 9bd1cc14c658e8de0e3a1156985993c623abda16..92dcd76975be6d2ee71c158a8fed2e687d0e58e2 100644 (file)
@@ -2874,6 +2874,32 @@ 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] == ':')
+    {
+       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);
+
+           if (auto_name != NULL)
+           {
+               ht = &globvarht;
+               ret = find_var_in_ht(ht, *name, auto_name, TRUE);
+               if (ret != NULL)
+               {
+                   if (htp != NULL)
+                       *htp = ht;
+                   return ret;
+               }
+           }
+           vim_free(auto_name);
+       }
+    }
+
     return NULL;
 }
 
@@ -3318,7 +3344,7 @@ set_var(
 }
 
 /*
- * Set variable "name" to value in "tv".
+ * Set variable "name" to value in "tv_arg".
  * When "sid" is non-zero "name" is in the script with this ID.
  * If the variable already exists and "is_const" is FALSE the value is updated.
  * Otherwise the variable is created.
index e9d94734a304596d1f05535f214658c0254e81b9..24aa28da2ac8a3f7a814d3bb43b01528e1a51422 100644 (file)
@@ -1091,7 +1091,7 @@ def Test_import_gone_when_sourced_twice()
 enddef
 
 " test using an auto-loaded function and variable
-def Test_vim9_autoload()
+def Test_vim9_autoload_full_name()
   var lines =<< trim END
      vim9script
      def some#gettest(): string
@@ -1146,11 +1146,16 @@ def Test_vim9script_autoload()
        return 'test'
      enddef
 
-     export func GetMore()
-       return Gettest() .. 'more'
+     export var name = 'name'
+
+     export func GetFunc()
+       return Gettest() .. 'more' .. s:name
      endfunc
 
-     export var name = 'name'
+     export def GetDef(): string
+       return Gettest() .. 'more' .. name
+     enddef
+
      export final fname = 'final'
      export const cname = 'const'
   END
@@ -1165,7 +1170,8 @@ def Test_vim9script_autoload()
       assert_equal('test', prefixed.Gettest())
       assert_equal(1, g:prefixed_loaded)
 
-      assert_equal('testmore', prefixed.GetMore())
+      assert_equal('testmorename', prefixed.GetFunc())
+      assert_equal('testmorename', prefixed.GetDef())
       assert_equal('name', prefixed.name)
       assert_equal('final', prefixed.fname)
       assert_equal('const', prefixed.cname)
@@ -1178,7 +1184,7 @@ def Test_vim9script_autoload()
   # can also get the items by autoload name
   lines =<< trim END
       call assert_equal('test', prefixed#Gettest())
-      call assert_equal('testmore', prefixed#GetMore())
+      call assert_equal('testmorename', prefixed#GetFunc())
       call assert_equal('name', prefixed#name)
       call assert_equal('final', prefixed#fname)
       call assert_equal('const', prefixed#cname)
index 2a2c3de50bd3b609c64957e525f765087764b3d6..ecfa17d4563982aa1e0c1b0a9fcb3763b7c1e8ed 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4083,
 /**/
     4082,
 /**/