]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script v8.2.2164
authorBram Moolenaar <Bram@vim.org>
Sat, 19 Dec 2020 20:23:42 +0000 (21:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 19 Dec 2020 20:23:42 +0000 (21:23 +0100)
Problem:    Vim9: autoload function doesn't work in script that starts with
            an upper case letter.
Solution:   Check for the autoload character. (closes #7502)

src/testdir/test_vim9_script.vim
src/userfunc.c
src/version.c

index 5949acbc606b6a7e7e181367eb5a645492a89b85..47ea43d3f8cfcd84b06db1921ade3beae38c7bf2 100644 (file)
@@ -2799,6 +2799,16 @@ def Test_vim9_autoload()
   g:some#other = 'other'
   assert_equal('other', g:some#other)
 
+  # upper case script name works
+  lines =<< trim END
+     vim9script
+     def Other#getOther(): string
+       return 'other'
+     enddef
+  END
+  writefile(lines, 'Xdir/autoload/Other.vim')
+  assert_equal('other', g:Other#getOther())
+
   delete('Xdir', 'rf')
   &rtp = save_rtp
 enddef
index 50088e6382ab633abfc8143cb6d25d78ecd5e7ed..31c7af3e70c53490cdbdfba7f5ce09fb2ed8fc1b 100644 (file)
@@ -2654,8 +2654,18 @@ trans_function_name(
        goto theend;
     }
 
-    // In Vim9 script a user function is script-local by default.
+    // In Vim9 script a user function is script-local by default, unless it
+    // starts with a lower case character: dict.func().
     vim9script = ASCII_ISUPPER(*start) && in_vim9script();
+    if (vim9script)
+    {
+       char_u *p;
+
+       // SomeScript#func() is a global function.
+       for (p = start; *p != NUL && *p != '('; ++p)
+           if (*p == AUTOLOAD_CHAR)
+               vim9script = FALSE;
+    }
 
     /*
      * Copy the function name to allocated memory.
index 8f2c50a9eb417412c36c002854b2a1a5cee830e8..a97037d510686065894cd9e9b6e48fdc3c10c166 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2164,
 /**/
     2163,
 /**/